There are some cases wherein digital zoom is required to implement in your Directshow camera application. For example, some camera modules support a few levels of optical zoom and user have a need of more zoom level apart from the supported camera optical zoom or some camera won’t support optical zoom at all. If this is your case, then this blog post can give you some pointers to implement the digital zoom in your Directshow camera application on window CE 6.0.
Using Directshow Renderer Filter
Renders are Directshow filters used to show the video preview on the specified window. See the following MSDN link to know about video render supported in Windows CE 6.0.In the aspect of render, the video stream input to the render is called as source video and the output given by the render is called as destination video.
Digital zoom is performed by cropping the required source video by playing with the pixel co-ordinates of source video, destination video and Window Coordinates. A question may rise in your mind that why we need window coordinates? Size of the object displayed on the screen should not be disturbed irrespective of the windows size changes. Also aspect ratio between the source and destination video should be maintained. Digital zoom can be achieved by cropping the required source video using SetSourcePostition() and displaying it on the preview windows with the required size using SetDestinationPostion(). The source video positions and destination video positions are calculated based on the required Zoom factor/levels.
There are lots of ways to calculate the source and destination positions based on the zoom factor, I shall leave the choice for selecting the algorithms to find the source and destination positions to you.
Let us see the interface and the functions used to change the source and destination video positions in the video render
IBasicVideo::SetSourcePosition() and IBasicVideo::SetDestinationPosition() are the two functions involved in changing the size of source and destination video size. The IBasicVideo interface can be accessed through the video render.
Steps Involved in Accessing these Functions.
- Since the DS filters are COM object, Load the render using CoCreateInstance().
hr = CoCreateInstance( CLSID_VideoRenderer, NULL, CLSCTX_INPROC_SERVER,
IID_IBaseFilter, (void**) &m_pVideoRenderer );
- Add the filter in the filter graph.
hr = m_pGraph->AddFilter(m_pVideoRenderer, TEXT(“VideoRenderer”));
- Query the IBasicVideo interface from the video renderer.
hr = m_pVideoRenderer.QueryInterface( &m_pVideoRendererBasicVideo );
Now you can access the SetSourcePosition() and SetDestinationPosition() during the preview rendering. Each method is using left, top, width and height as a parameter. GetVideoSize() method is used to receive the maximum source video size for the corresponding resolution. Using these APIs you can perform digital zoom effectively.
Vinoth Rajagopalan is an embedded vision expert with 15+ years of experience in product engineering management, R&D, and technical consultations. He has been responsible for many success stories in e-con Systems – from pre-sales and product conceptualization to launch and support. Having started his career as a software engineer, he currently leads a world-class team to handle major product development initiatives