如何编程控制射相头,要求能启动射相头并进行拍照等功能。

安馨安旭 2007-08-16 11:24:47
如题,射相头只需要是目前市场上很普通很通用的就可以了,找了好多地方都没找到这类资料,希望各位帮下忙!
...全文
755 32 打赏 收藏 转发到动态 举报
写回复
用AI写文章
32 条回复
切换为时间正序
请发表友善的回复…
发表回复
belllab 2007-08-23
  • 打赏
  • 举报
回复
如果采集为AVI文件,而且不压缩的话,文件体积是比较大的,所以最好使用压缩技术。
naiza 2007-08-23
  • 打赏
  • 举报
回复
mark
lih163 2007-08-22
  • 打赏
  • 举报
回复
xx
安馨安旭 2007-08-22
  • 打赏
  • 举报
回复
看来没人可以解释了,算了,结帖吧!
spark_li 2007-08-21
  • 打赏
  • 举报
回复
mark
marrco2005 2007-08-21
  • 打赏
  • 举报
回复
mark
FFSB 2007-08-20
  • 打赏
  • 举报
回复
要想保存成DVD/VCD格式用DirectShow方便
安馨安旭 2007-08-20
  • 打赏
  • 举报
回复
不是说你,是说你楼上的。
FFSB 2007-08-20
  • 打赏
  • 举报
回复
希望LZ不是说我...
安馨安旭 2007-08-20
  • 打赏
  • 举报
回复
不知道你把他的代码帖出来是什么意思,前面他已经给出链接了,我问的是如何解决那个C++代码录象占的空间非常大的解决办法。
FFSB 2007-08-20
  • 打赏
  • 举报
回复
上面的代码默认是0通道 320*240
如果是多通道电视卡或采集卡就不行鸟
yimawww 2007-08-20
  • 打赏
  • 举报
回复
unit1.h里的声明:
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
public: // User declarations
enum PLAYSTATE {Stopped, Paused, Running, Init};
__fastcall TForm1(TComponent* Owner);
__fastcall ~TForm1();
protected: // User declarations
void __fastcall WndProc(Messages::TMessage &Message);
private: // User declarations
DWORD g_dwGraphRegister;
IVideoWindow * g_pVW;
IMediaControl * g_pMC;
IMediaEventEx * g_pME;
IGraphBuilder * g_pGraph;
ICaptureGraphBuilder2 * g_pCapture;
PLAYSTATE g_psCurrent;

void Msg(TCHAR *szFormat, ...);
void RemoveGraphFromRot(DWORD pdwRegister);
HRESULT AddGraphToRot(IUnknown *pUnkGraph, DWORD *pdwRegister);
HRESULT GetInterfaces(void);
void CloseInterfaces(void);
HRESULT FindCaptureDevice(IBaseFilter ** ppSrcFilter);
void ResizeVideoWindow(void);
HRESULT SetupVideoWindow(void);
HRESULT CaptureVideo();
HRESULT ChangePreviewState(int nShow);
HRESULT HandleGraphEvent(void);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
yimawww 2007-08-20
  • 打赏
  • 举报
回复
(接上条)
HRESULT TForm1::CaptureVideo()
{
HRESULT hr;
IBaseFilter *pSrcFilter=NULL;

// Get DirectShow interfaces
hr = GetInterfaces();
if (FAILED(hr))
{
Msg(TEXT("Failed to get video interfaces! hr=0x%x"), hr);
return hr;
}

// Attach the filter graph to the capture graph
hr = g_pCapture->SetFiltergraph(g_pGraph);
if (FAILED(hr))
{
Msg(TEXT("Failed to set capture filter graph! hr=0x%x"), hr);
return hr;
}

// Use the system device enumerator and class enumerator to find
// a video capture/preview device, such as a desktop USB video camera.
hr = FindCaptureDevice(&pSrcFilter);
if (FAILED(hr))
{
// Don't display a message because FindCaptureDevice will handle it
return hr;
}

// Add Capture filter to our graph.
hr = g_pGraph->AddFilter(pSrcFilter, L"Video Capture");
if (FAILED(hr))
{
Msg(TEXT("Couldn't add the capture filter to the graph! hr=0x%x\r\n\r\n")
TEXT("If you have a working video capture device, please make sure\r\n")
TEXT("that it is connected and is not being used by another application.\r\n\r\n")
TEXT("The sample will now close."), hr);
pSrcFilter->Release();
return hr;
}

// Render the preview pin on the video capture filter
// Use this instead of g_pGraph->RenderFile
hr = g_pCapture->RenderStream (&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video,
pSrcFilter, NULL, NULL);
if (FAILED(hr))
{
Msg(TEXT("Couldn't render the video capture stream. hr=0x%x\r\n")
TEXT("The capture device may already be in use by another application.\r\n\r\n")
TEXT("The sample will now close."), hr);
pSrcFilter->Release();
return hr;
}

// Now that the filter has been added to the graph and we have
// rendered its stream, we can release this reference to the filter.
pSrcFilter->Release();

// Set video window style and position
hr = SetupVideoWindow();
if (FAILED(hr))
{
Msg(TEXT("Couldn't initialize video window! hr=0x%x"), hr);
return hr;
}

#ifdef REGISTER_FILTERGRAPH
// Add our graph to the running object table, which will allow
// the GraphEdit application to "spy" on our graph
hr = AddGraphToRot(g_pGraph, &g_dwGraphRegister);
if (FAILED(hr))
{
Msg(TEXT("Failed to register filter graph with ROT! hr=0x%x"), hr);
g_dwGraphRegister = 0;
}
#endif

// Start previewing video data
hr = g_pMC->Run();
if (FAILED(hr))
{
Msg(TEXT("Couldn't run the graph! hr=0x%x"), hr);
return hr;
}

// Remember current state
g_psCurrent = Running;

return S_OK;
}
//---------------------------------------------------------------------------
HRESULT TForm1::ChangePreviewState(int nShow)
{
HRESULT hr=S_OK;

// If the media control interface isn't ready, don't call it
if (!g_pMC)
return S_OK;

if (nShow)
{
if (g_psCurrent != Running)
{
// Start previewing video data
hr = g_pMC->Run();
g_psCurrent = Running;
}
}
else
{
// Stop previewing video data
hr = g_pMC->StopWhenReady();
g_psCurrent = Stopped;
}

return hr;
}
//---------------------------------------------------------------------------
HRESULT TForm1::HandleGraphEvent(void)
{
LONG evCode, evParam1, evParam2;
HRESULT hr=S_OK;

if (!g_pME)
return E_POINTER;

while(SUCCEEDED(g_pME->GetEvent(&evCode, (LONG_PTR *) &evParam1,
(LONG_PTR *) &evParam2, 0)))
{
//
// Free event parameters to prevent memory leaks associated with
// event parameter data. While this application is not interested
// in the received events, applications should always process them.
//
hr = g_pME->FreeEventParams(evCode, evParam1, evParam2);

// Insert event processing code here, if desired
}

return hr;
}
//---------------------------------------------------------------------------
yimawww 2007-08-20
  • 打赏
  • 举报
回复
接上条:
void TForm1::CloseInterfaces(void)
{
// Stop previewing data
if (g_pMC)
g_pMC->StopWhenReady();

g_psCurrent = Stopped;

// Stop receiving events
if (g_pME)
g_pME->SetNotifyWindow(NULL, WM_GRAPHNOTIFY, 0);

// Relinquish ownership (IMPORTANT!) of the video window.
// Failing to call put_Owner can lead to assert failures within
// the video renderer, as it still assumes that it has a valid
// parent window.
if(g_pVW)
{
g_pVW->put_Visible(OAFALSE);
g_pVW->put_Owner(NULL);
}

#ifdef REGISTER_FILTERGRAPH
// Remove filter graph from the running object table
if (g_dwGraphRegister)
RemoveGraphFromRot(g_dwGraphRegister);
#endif

// Release DirectShow interfaces
SAFE_RELEASE(g_pMC);
SAFE_RELEASE(g_pME);
SAFE_RELEASE(g_pVW);
SAFE_RELEASE(g_pGraph);
SAFE_RELEASE(g_pCapture);
}
//---------------------------------------------------------------------------
HRESULT TForm1::FindCaptureDevice(IBaseFilter ** ppSrcFilter)
{
HRESULT hr;
IBaseFilter * pSrc = NULL;
CComPtr <IMoniker> pMoniker =NULL;
ULONG cFetched;

if (!ppSrcFilter)
return E_POINTER;

// Create the system device enumerator
CComPtr <ICreateDevEnum> pDevEnum =NULL;

hr = CoCreateInstance (CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC,
IID_ICreateDevEnum, (void **) &pDevEnum);
if (FAILED(hr))
{
Msg(TEXT("Couldn't create system enumerator! hr=0x%x"), hr);
return hr;
}

// Create an enumerator for the video capture devices
CComPtr <IEnumMoniker> pClassEnum = NULL;

hr = pDevEnum->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, &pClassEnum, 0);
if (FAILED(hr))
{
Msg(TEXT("Couldn't create class enumerator! hr=0x%x"), hr);
return hr;
}

// If there are no enumerators for the requested type, then
// CreateClassEnumerator will succeed, but pClassEnum will be NULL.
if (pClassEnum == NULL)
{
MessageBox(Handle,TEXT("No video capture device was detected.\r\n\r\n")
TEXT("This sample requires a video capture device, such as a USB WebCam,\r\n")
TEXT("to be installed and working properly. The sample will now close."),
TEXT("No Video Capture Hardware"), MB_OK | MB_ICONINFORMATION);
return E_FAIL;
}

// Use the first video capture device on the device list.
// Note that if the Next() call succeeds but there are no monikers,
// it will return S_FALSE (which is not a failure). Therefore, we
// check that the return code is S_OK instead of using SUCCEEDED() macro.
if (S_OK == (pClassEnum->Next (1, &pMoniker, &cFetched)))
{
// Bind Moniker to a filter object
hr = pMoniker->BindToObject(0,0,IID_IBaseFilter, (void**)&pSrc);
if (FAILED(hr))
{
Msg(TEXT("Couldn't bind moniker to filter object! hr=0x%x"), hr);
return hr;
}
}
else
{
Msg(TEXT("Unable to access video capture device!"));
return E_FAIL;
}

// Copy the found filter pointer to the output parameter.
// Do NOT Release() the reference, since it will still be used
// by the calling function.
*ppSrcFilter = pSrc;

return hr;
}
//---------------------------------------------------------------------------
void TForm1::ResizeVideoWindow(void)
{
// Resize the video preview window to match owner window size
if (g_pVW)
{
RECT rc;

// Make the preview video fill our window
::GetClientRect(Handle, &rc);
g_pVW->SetWindowPosition(0, 0, rc.right, rc.bottom);
}
}
//---------------------------------------------------------------------------
HRESULT TForm1::SetupVideoWindow(void)
{
HRESULT hr;

// Set the video window to be a child of the main window
hr = g_pVW->put_Owner((OAHWND)Handle);
if (FAILED(hr))
return hr;

// Set video window style
hr = g_pVW->put_WindowStyle(WS_CHILD | WS_CLIPCHILDREN);
if (FAILED(hr))
return hr;

// Use helper function to position video window in client rect
// of main application window
ResizeVideoWindow();

// Make the video window visible, now that it is properly positioned
hr = g_pVW->put_Visible(OATRUE);
if (FAILED(hr))
return hr;

return hr;
}
//---------------------------------------------------------------------------
yimawww 2007-08-20
  • 打赏
  • 举报
回复
这是杰子给的演示程序里的源码。
你试试看。
//---------------------------------------------------------------------------
#include <atl/atlbase.h>
#include <vcl.h>
#include <stdio.h>

#pragma hdrstop

#include <dshow.h>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
#pragma link "amstrmid.lib"
TForm1 *Form1;
//---------------------------------------------------------------------------



#define REGISTER_FILTERGRAPH
//---------------------------------------------------------------------------
// Application-defined message to notify app of filtergraph events
#define WM_GRAPHNOTIFY WM_APP+1

#define SAFE_RELEASE(x) { if (x) x->Release(); x = NULL; }

#define JIF(x) if (FAILED(hr=(x))) \
{Msg(TEXT("FAILED(hr=0x%x) in ") TEXT(#x) TEXT("\n\0"), hr); return hr;}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
g_dwGraphRegister=0;
g_pVW = NULL;
g_pMC = NULL;
g_pME = NULL;
g_pGraph = NULL;
g_pCapture = NULL;
g_psCurrent = Stopped;

if(FAILED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED))) //Initialize COM
{
Msg(TEXT("CoInitialize Failed!\r\n"));
Application->Terminate();
return;
}
if(FAILED(CaptureVideo()))
{
Application->Terminate();
return;
}
}
//---------------------------------------------------------------------------
__fastcall TForm1::~TForm1()
{
CloseInterfaces();
CoUninitialize(); // Release COM
}
//---------------------------------------------------------------------------
void __fastcall TForm1::WndProc(Messages::TMessage &Message)
{
switch(Message.Msg)
{
case WM_GRAPHNOTIFY:
HandleGraphEvent();
break;

case WM_SIZE:
ResizeVideoWindow();
break;

case WM_WINDOWPOSCHANGED:
ChangePreviewState(!(IsIconic(Handle)));
break;

case WM_CLOSE:
// Hide the main window while the graph is destroyed
ShowWindow(Handle, SW_HIDE);
CloseInterfaces(); // Stop capturing and release interfaces
break;

case WM_DESTROY:
PostQuitMessage(0);
Message.Result = 0;
return;
}

// Pass this message to the video window for notification of system changes
if (g_pVW)
g_pVW->NotifyOwnerMessage((LONG_PTR)Handle, Message.Msg, Message.WParam, Message.LParam);

TForm::WndProc(Message);
}
//---------------------------------------------------------------------------
void TForm1::Msg(TCHAR *szFormat, ...)
{
TCHAR szBuffer[1024]; // Large buffer for long filenames or URLs
const size_t NUMCHARS = sizeof(szBuffer) / sizeof(szBuffer[0]);
const int LASTCHAR = NUMCHARS - 1;

// Format the input string
va_list pArgs;
va_start(pArgs, szFormat);


_vsntprintf(szBuffer, NUMCHARS - 1, szFormat, pArgs);
va_end(pArgs);

// Ensure that the formatted string is NULL-terminated
szBuffer[LASTCHAR] = TEXT('\0');

MessageBox(NULL, szBuffer, TEXT("PlayCap Message"), MB_OK | MB_ICONERROR);
}
//---------------------------------------------------------------------------
#ifdef REGISTER_FILTERGRAPH // { //
//---------------------------------------------------------------------------
// Removes a filter graph from the Running Object Table
void TForm1::RemoveGraphFromRot(DWORD pdwRegister)
{
IRunningObjectTable *pROT;

if (SUCCEEDED(GetRunningObjectTable(0, &pROT)))
{
pROT->Revoke(pdwRegister);
pROT->Release();
}
}
//---------------------------------------------------------------------------
HRESULT TForm1::AddGraphToRot(IUnknown *pUnkGraph, DWORD *pdwRegister)
{
IMoniker * pMoniker;
IRunningObjectTable *pROT;
WCHAR wsz[128];
HRESULT hr;

if (!pUnkGraph || !pdwRegister)
return E_POINTER;

if (FAILED(GetRunningObjectTable(0, &pROT)))
return E_FAIL;

wsprintfW(wsz, L"FilterGraph %08x pid %08x\0", (DWORD_PTR)pUnkGraph,
GetCurrentProcessId());

hr = CreateItemMoniker(L"!", wsz, &pMoniker);
if (SUCCEEDED(hr))
{
hr = pROT->Register(ROTFLAGS_REGISTRATIONKEEPSALIVE, pUnkGraph,
pMoniker, pdwRegister);
pMoniker->Release();
}

pROT->Release();
return hr;
}
//---------------------------------------------------------------------------
#endif // } //
//---------------------------------------------------------------------------
HRESULT TForm1::GetInterfaces(void)
{
HRESULT hr;

// Create the filter graph
hr = CoCreateInstance (CLSID_FilterGraph, NULL, CLSCTX_INPROC,
IID_IGraphBuilder, (void **) &g_pGraph);
if (FAILED(hr))
return hr;

// Create the capture graph builder
hr = CoCreateInstance (CLSID_CaptureGraphBuilder2 , NULL, CLSCTX_INPROC,
IID_ICaptureGraphBuilder2, (void **) &g_pCapture);
if (FAILED(hr))
return hr;

// Obtain interfaces for media control and Video Window
hr = g_pGraph->QueryInterface(IID_IMediaControl,(LPVOID *) &g_pMC);
if (FAILED(hr))
return hr;

hr = g_pGraph->QueryInterface(IID_IVideoWindow, (LPVOID *) &g_pVW);
if (FAILED(hr))
return hr;

hr = g_pGraph->QueryInterface(IID_IMediaEvent, (LPVOID *) &g_pME);
if (FAILED(hr))
return hr;

// Set the window handle used to process graph events
hr = g_pME->SetNotifyWindow((OAHWND)Handle, WM_GRAPHNOTIFY, 0);

return hr;
}
//---------------------------------------------------------------------------
安馨安旭 2007-08-18
  • 打赏
  • 举报
回复
我也发现我的录制的录象非常的大,1秒有10MB的样子,希望有高手帮解决下。
laowang2 2007-08-18
  • 打赏
  • 举报
回复
up
安馨安旭 2007-08-17
  • 打赏
  • 举报
回复
昨天回去试了下,C++代码的那个可以实现基本功能,效果还可以。那个BCB6的看不了代码,就没怎么弄。安吉儿所说的VFW控件没找到下载地方,只看见有人介绍在Delphi中使用VFW的例子。
过两天再搞个清晰点的摄像头试一下,并完善一下程序,如果没问题就结贴了。
顺便问一下,有大半年没来CSDN了,确实变漂亮了好多,但是却发现新版的可用分不涨,难道不是每天登陆一次就张一次么?老版里有好多分,能转到新版来么?
hansyswin 2007-08-17
  • 打赏
  • 举报
回复
mark
coolcalf 2007-08-17
  • 打赏
  • 举报
回复
杰子提供的代码实现了视频捕获抓图及录制,以及进行视频相关设置。
但还是存在些小问题,有时候点了没反应,或抓图为0字节,不明白。

代码中不包含数据压缩,录制简单10秒AVI居然上百兆。
加载更多回复(12)

1,317

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 网络及通讯开发
社区管理员
  • 网络及通讯开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧