|
I want to build this project for WinCE6.0,but have a lots error.
I think it must be something wrong,Can Somebody help me?
|
|
|
|
|
Hi Angel,
Thanks for sharing your nice works.
I have tried your programs on my LG GM750 phone running Windows Mobile 6.5. The camera's output format is YV12 and so I have changed MEDIASUBTYPE_RGB24 to MEDIASUBTYPE_RGB565 in CSampleGrabber::CheckInputType and SampleGrabber::SetMediaType, and Format24bppRgb to Format16bppRgb565 in CreateBitmap and OnMediaTypeSet in the C# program.
When deploying the projects into my smartphone, I could see a blurred image on the screen. When I place a finger horizontally in front of the camera, I could see a very blurred and much elongated finger-like shape. When I move my finger up and down, the blurred and elongated shape moves up and down too.
I think that the raw data from the camera may be mis-interpreted when they are copied to the screen but I have no idea where should I try to change the parameters. One point I suspected is that the "stride" size may be different when using RGB565 mode, i.e.
in SampleGrabber.cpp,
DWORD dwStride = (vih->bmiHeader.biWidth * (vih->bmiHeader.biBitCount / 8) + 3) & ~3;
This dwStride may have to be assigned a different value for the programs to work correctly. However, I have no idea how it should be assigned and perhaps there is other parameter that should be changed too.
Could I have some advices on how these parameters should be changed. Thanks for your attention.
Regards
Lawrence
|
|
|
|
|
My issue is solved through the use of Color Space Converter Filter.
|
|
|
|
|
Angel:
I have crash in the following sentence:
CHK( CoCreateInstance( CLSID_SampleGrabber, NULL, CLSCTX_INPROC, IID_IBaseFilter, (void**)&pH263Transform ) );
after that the line of debugger stop at the line of amfilter.cpp located at:
C:\WINCE500\PUBLIC\DIRECTX\SDK\SAMPLES\DSHOW\BASECLASSES\amfilter.cpp
if (m_pClock) {
m_pClock->Release();
}
with the message "Unhandled exception at 0x017e7fa4 in TestCameraCapture.exe: 0xC0000005: Access violation reading location 0x00000004."
I am really crazy with it.
I think maybe that the filter didn't register.
I am using Windows Mobile 6 profesional con WINCE50 and visual studio 2008
thanks in advance
Jose Anaya M
|
|
|
|
|
Can you please explain the process for registering this DLL. Why is it necessary? Register it on the development machine or on the Windows Mobile device?
Thanks,
-fakepoo
|
|
|
|
|
You need to register the DLL in order for it to be used by other programs on the OS. The registration consists of creating some Registry entries, which other components read to find out wrich DirectShow filters are installed on the system.
|
|
|
|
|
I tried to execute your Samplecameracapture dll code on windows mobile 6.1 device
but it's giving error at following line
CHK( m_pCaptureGraphBuilder->RenderStream(&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video, m_pVideoCaptureFilter, pH263Transform, NULL ) );
howerver it's working fine on win mo emulator.
I registered CameraCaptureDLL.dll successfully on win mo 6.1 device but still it's giving error at above line.
Please help.
modified on Sunday, November 28, 2010 3:33 AM
|
|
|
|
|
Hi,
Thanks for sharing the code. Being new to WM development, this helped a great deal.
I encountered a problem when trying to register the callback using the UI. The error displayed is as follow:
"A first chance exception of type 'System.IO.IOException' occurred in mscorlib.dll
A first chance exception of type 'System.NotSupportedException' occurred in System.Drawing.dll
The thread 0x376de0e has exited with code 0 (0x0)."
The only section of the code which was modified, were the picturebox and panel.
When executed,
- UI running
- Preview running
- Menu and buttons works
Any advice would be greatly appreciated.
[Update]
I have found the reason for the errors. It seems the Log(String) function can't be run within the callback functions. Since its not critical, the line of code was just commented off.
Currently, I have modified the transform() in CSampleGrabber to save the frame to a bitmap. The resolution is always tiny and the RGB colors seems incorrect. Have tried to change the resolution through the use of IAMStreamConfig within graphmanager. To be safe, I changed the resolution using 2 methods. Not sure if I had done any mistake, I have attached the code for your advice.
=================================================================
[Used before the filters were connected with RenderStream]
-----------------------------------------------------------------
hr = m_pVideoCaptureFilter?m_pVideoCaptureFilter->EnumPins(&pins) ;
hr = pins?pins->Next(1, &pin, 0) ;
hr = pin->QueryInterface(IID_IAMStreamConfig, (void**)&cfg);
hr = cfg->GetNumberOfCapabilities(&max_res, &res_size);
hr = cfg->GetStreamCaps(7, &fmt, (BYTE*)cap);
hr = cfg->SetFormat(fmt);
==================================================================
[Seperate method used to call after graph is running]
------------------------------------------------------------------
m_pCaptureGraphBuilder->FindInterface(NULL, &MEDIATYPE_Video,
m_pVideoCaptureFilter, IID_IAMStreamConfig, (void**)&pConfig);
pConfig->GetNumberOfCapabilities(&iCount, &iSize);
/* Mode is set to desired resolution */
pConfig->GetStreamCaps(mode, &pmtConfig, (BYTE*)&scc);
pConfig->SetFormat(pmtConfig);
DeleteMediaType(pmtConfig);
The code above had been tested and logged. Checking for "S_OK" after setformat has been called, the resolution indicated has been changed to 320,240. However the bitmap saved is of a different resolution with distorted colors.
|
|
|
|
|
Some things that I will like to explain regarding this:
Changing resolution while the graph is running has no effect. Although it states S_OK, nothing will be changed in the video stream. The graph needs to be stopped before you can change the resolution.
After you use renderstream to connect the videocapturefilter, samplegrabber together. You should use this set of code to set your resolution:
m_pCaptureGraphBuilder->FindInterface(NULL, &MEDIATYPE_Video,
m_pVideoCaptureFilter, IID_IAMStreamConfig, (void**)&pConfig);
pConfig->GetNumberOfCapabilities(&iCount, &iSize);
/* Mode is set to desired resolution */
pConfig->GetStreamCaps(mode, &pmtConfig, (BYTE*)&scc);
pConfig->SetFormat(pmtConfig);
DeleteMediaType(pmtConfig);
After that is done, you should use m_pMediaControl->Run() to start the video stream.
Ignore the set of codes that you used[Used before the filters were connected with RenderStream].
As for distorted colors, main reason is that the memory allocated for the bitmap in your C# program is of a different resolution from the bitmap that was captured. That will explain the distortion, because there will definitely be pixels that are mapped onto the wrong location.
modified on Sunday, October 17, 2010 3:14 AM
|
|
|
|
|
Thanks for your feedback =D
[Status]
Problem solved. Silly mistake was that the PIN was set to preview instead of capture. After changing it to PIN_CATEGORY_CAPTURE the resolution size was able to be set. Reasons in detail I'm not too sure. However attempts to change the subtype failed, therefore the default YV12 was used.
"CHK( m_pCaptureGraphBuilder->RenderStream( &PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video, m_pVideoCaptureFilter, pH263Transform, NULL ) );"
As for the distortion, it is still an issue. Let me explain abit more, as I did not use the callback function. The process of saving the bmp file was done in CSampleGrabber::Transform function. The code I had added is as follows:
"HANDLE fh = CreateFile(filePath, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, NULL, NULL);
BITMAPFILEHEADER bfh;
memset(&bfh, 0, sizeof(bfh));
bfh.bfType = 'MB';
bfh.bfSize = sizeof(bfh) + sizeof(BITMAPINFOHEADER) + lSize;
bfh.bfOffBits = sizeof(bfh) + sizeof(BITMAPINFOHEADER);
DWORD nWritten = 0;
WriteFile(fh, &bfh, sizeof(bfh), &nWritten, NULL);
BITMAPINFOHEADER bih;
memset(&bih, 0, sizeof(bih));
bih.biSize = sizeof(bih);
bih.biWidth = m_Width;
bih.biHeight = m_Height;
bih.biPlanes = 1;
bih.biClrImportant = 0;
bih.biClrUsed = 0;
bih.biBitCount = (WORD)m_Bit;
nWritten = 0;
WriteFile(fh, &bih, sizeof(bih), &nWritten, NULL);
nWritten = 0;
WriteFile(fh, pCurrentBits, lSize, &nWritten, NULL);
CloseHandle(fh);"
The values for m_Width, m_Height and m_Bit are derived when the function CSampleGrabber::SetMediaType is called. Currently subtype MEDIASUBTYPE_RGB565 is used instead of MEDIASUBTYPE_YV12. In RGB565 the video preview is perfect, but when YV12 is used the video window merely appears as a black box.
Once again, any comments and advice is greatly appreciated.
|
|
|
|
|
Renderstream automatically inserts a color converter filter after your video capture filter. That will automatically convert your YV12 to RGB565 format. No other possible conversion are available for YV12 format except RGB565.
|
|
|
|
|
[Question]
Does that mean in the given scenario below:
"RenderStream( &PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, m_pVideoCaptureFilter, pH263Transform, NULL )"
A color filter is inserted after m_pVideoCaptureFilter?
[Status]
I tried checking and permitting MEDIASUBTYPE_YV12 in functions
CSampleGrabber::CheckInputType and CSampleGrabber::SetMediaType, but the application will crash when capturing is started. I am able to capture a couple of files before it crashes, and with the use of a yuv viewer, I discovered that the UV properties were inverted causing color distortion. Given the same scenario, and MEDIASUBTYPE_RGB565 is used, the preview and application is fine. However, the file captured is badly distorted.
I suspect that CSampleGrabber might be recieving RGB565 and I am not saving it properly into a bmp file.
Please advice me on an approach to capture the frame.
Sincerely appreciate your prompt response.
|
|
|
|
|
Yes using
RenderStream( &PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, m_pVideoCaptureFilter, pH263Transform, NULL )
will automatically insert a color converter filter inside. You only need to check for RGB565 images. The color converter filter will be inserted between the videocapturefilter and the samplegrabber.
|
|
|
|
|
Thanks for the info.
[Status]
Could not figure out how to set to a format needed, thus stayed with RGB565 16bit. Managed to save the frame to bmp file format.
And thats a WRAP! =D
Thanks once again for your assistance.
|
|
|
|
|
To say the truth, most phones only have 1 available format. E.g if your phone doesn't have RGB24, it is not possible for you to set it at all.
If you do not wish to stick to RGB565, you can try to connect the pins between the filters without RenderStream. It will allow you to use the YV12 format. Only drawback of this is that, you have to specifically obtain the pins of the rendering filter to get a preview.
|
|
|
|
|
Hi there,
I am trying to use the FrameGrabber in my own Project, however I have stumbled upon a problem.
I am using RenderStream() to connect the videoCaptureFilter with the SampleGrabber filter like so:
hr=_captureGraphBuilder->RenderStream(&PIN_CATEGORY_PREVIEW,&MEDIATYPE_Video,_videoCaptureFilter,pSampleGrabber, NULL);
Running this on a Windows Mobile Emulator works just fine. On an actual device however(HTC HD2 for example) this does not work and returns E_FAIL.
Does anyone have any ideas as to the reason for this behaviour?
Thanks for your help!
|
|
|
|
|
The RenderStream function should be working fine, unless your HTC HD2 does not have a preview pin, which is not very possible. It is best for you to post the whole section of your code where you initialized your samplegrabber before we can help to analyze the problem for you. It might be also possible that your samplegrabber is not initialized, but then the same problem will happen to the emulator as well.
|
|
|
|
|
Hi,
Encountered the same problem initially, but have been reading through the posts and got it to preview on the actual device (HTC HD2).
Modifications made were just to the RGB type. Can't remember where the modifications are so you might need to do a find for [PixelFormat.Format24bppRgb].
"PixelFormat.Format24bppRgb -> PixelFormat.Format16bppRgb565"
Hope this helps.
|
|
|
|
|
hi,
at first, thanks a lot for your work, I can now grab frame data on my HTC HD2!
But the problem is that the dll is only using the smallest possible resolution. I saw that in CGraphManager::StartCaptureFramesInternal() there are already these lines of code, which seem to be the beginning of a resolution-changing algorithm:
CComPtr<IAMStreamConfig> pConfig;
int iCount = 0;
int iSize = 0;
int dwId = 0;
If added the following code after that:
dwId = 7;
hr = m_pCaptureGraphBuilder->FindInterface(NULL, &MEDIATYPE_Video,
m_pVideoCaptureFilter, IID_IAMStreamConfig, (void**)&pConfig);
hr = pConfig->GetNumberOfCapabilities(&iCount, &iSize);
if (SUCCEEDED(hr) && (iSize == sizeof(VIDEO_STREAM_CONFIG_CAPS)) && (dwId < iCount))
{
VIDEO_STREAM_CONFIG_CAPS scc;
AM_MEDIA_TYPE *pmtConfig;
hr = pConfig->GetStreamCaps(dwId, &pmtConfig, (BYTE*)&scc);
if (SUCCEEDED(hr))
{
hr = pConfig->SetFormat(pmtConfig);
DeleteMediaType(pmtConfig);
}
}
Everything seems to be alright, and when I go through that part in debugging, I get for example a resolution of 320x240 in scc for dwId = 7, which should be ok. The only problem is that the resolution of my output image stays the same tiny one, no matter what I do!
Do you know what I am doing wrong?
|
|
|
|
|
Nothing is wrong with your code. I think the problem in your case lies in the fact that you did not resize your picturebox or panel, which might be why the resolution remains at 176x144.
Further possible problems is that you tried to change your resolution while your graph is running. Ensure that your graph is stopped before you change resolution.
modified on Sunday, October 24, 2010 2:44 AM
|
|
|
|
|
Hi All,
Firstly, Thanks to the author for the sample code !!!
I am having the following error while trying to compile this code:
unresolved external symbol "public: virtual unsigned long __cdecl CBaseFilter::NonDelegatingRelease(void)"
Angel has mentioned that version "26.08.2008 v1.1 Created. " has the NonDelegatingRelease added, but am unable to locate the source. Any help would be useful.
Best,
Surya
|
|
|
|
|
I am also having this same problem. Any help would be great.
Linda
|
|
|
|
|
add the following code to your CSampleGrabber public method declaration.
ULONG CBaseFilter::NonDelegatingRelease(void)
{
return 1;
}
|
|
|
|
|
hi everybody,
this is my sample code
IGraphBuilder *pGraph;
IBaseFilter *pGrabberF;
ISampleGrabber *pGrabber;
// create the Sample Grabber filter.
1) hr = CoCreateInstance( CLSID_GrabberSample, NULL, CLSCTX_INPROC,
IID_IBaseFilter, (void**)&pGrabberF);
if(FAILED(hr))
goto done;
2) hr = pGraph->AddFilter(pGrabberF, L"Sample Grabber");
if(FAILED(hr))
goto done;
//get a point to the interface
hr = pGrabberF->QueryInterface(IID_IGrabberSample, (void **)&pGrabber);
if(FAILED(hr))
goto done;
i just want to instantiate pGrabberF. the fact is that it always fails in step 1 in
debug modle.does anyone know how to solve the problem?
thanks a lot!
|
|
|
|
|
If it hangs at step 1, most likely its the way you defined your CLSID_GrabberSample. Check your code and make sure you don't call "initguid.h" more than 2 times. If you already included "initguid.h" in your grabbersample's .h or .cpp file, then make sure you don't call it again in your main program.
|
|
|
|
|