Solved

How to write a WebCam application using Directshow to preview and capture in portrait and landscape mode?

Posted on 2009-04-06
9
990 Views
Last Modified: 2013-12-08
     I have written an application using C Plus Plus and  DirectShow that can preview and capture images in landscape mode. I dont know how to change the mode from landscape to portrait. So the application can do preview and capture for resolutions such as 800x600 or 1200x900. But what I need is, the application should also be able to do preview and capture for resolutions such as 900x1200 or 600x800. We thought of rotating the stream by 90 degrees but it isn't actually a solution.

        I tried to find the solution over net but unsuccessful. I think the Camera in itself need to support the portrait resolutions such as 900x1200 along with the landscape resolutions but I could not find a justifying referece to confirm it.

        Any help in this issue is highly appreciated.
0
Comment
Question by:rahul_r_jadhav
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
9 Comments
 
LVL 7

Accepted Solution

by:
HalfAsleep earned 500 total points
ID: 24155849
You are right when you say that the resolution comes from the camera.  You have to find out if your camera that supplies the stream, can be told what resolution to use.  If your camera does not support the resolution you want, you will not be able to get that resolution for your camera stream directly.

You can of course crop the landscape stream, to make it appear to be a portrait.  This means losing some fidelity/resolution.
0
 
LVL 7

Expert Comment

by:HalfAsleep
ID: 24155897
In c#, I did the following to get my webcams capabilities, but I am not sure I can change them, they come directly from the camera...

                hr = sampleGrabber.GetConnectedMediaType(media);
                if( hr < 0 )
                {
                    DsError.ThrowExceptionForHR(hr);
                }
                if( (media.formatType != FormatType.VideoInfo) || (media.formatPtr == IntPtr.Zero) )
                {
                    throw new NotSupportedException("Unknown Grabber Media Format");
                }
 
                this.videoInfoHeader = (VideoInfoHeader)Marshal.PtrToStructure(media.formatPtr, typeof(VideoInfoHeader));
                this.snapShotWidth = this.videoInfoHeader.BmiHeader.Width;
                this.snapShotHeight = this.videoInfoHeader.BmiHeader.Height;
                this.snapShotImageSize = this.videoInfoHeader.BmiHeader.Imag

Open in new window

0
 
LVL 7

Expert Comment

by:HalfAsleep
ID: 24156189
This may help a bit...

http://msdn.microsoft.com/en-us/library/dd407324(VS.85).aspx

I also found these pages extremely helpful when I was doing some webcam development, but I am not sure if you will be able to find too much on resolutions in there.  I think you can enumerate some resolutions you want if you use the first link.  It is up to the camera/driver to agree or not though, you can only request what you want, but it has the final word.

http://msdn.microsoft.com/en-us/library/dd407331(VS.85).aspx
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:rahul_r_jadhav
ID: 24168357
Hi!!
   Thanks for your time. I have done all these coding such as - getting the capabilities/ resolutions etc. Other things are working fine, there is no issue in that. Cropping, I dont think will really help. You said "If your camera does not support the resolution you want, you will not be able to get that resolution for your camera stream directly.". My understanding is also same. I think if camera doesnt support it, whatever you do in filter graph etc you can not get portrait mode. But my difficulty is that I could not find any proof that will proove this point. By any chance have you come accross any such statement.

   
 
0
 
LVL 7

Expert Comment

by:HalfAsleep
ID: 24169172
I do not have any proof, other than my own experiences.
0
 
LVL 2

Author Comment

by:rahul_r_jadhav
ID: 24203768
Hi HalfAsleep,
 
          Still thanks for your time and help.
0
 
LVL 7

Expert Comment

by:HalfAsleep
ID: 24207176
No problem ;) That is what this is all about, helping each other.
0
 
LVL 7

Expert Comment

by:HalfAsleep
ID: 25320012
I feel I have answered the question fairly well, although I could not give extensive "proof" other than my experiences.  Since noone else have contributed, I feel I should at least get some credit, and my links and code will be helpful for others looking for the same issues regarding webcam development.
0

Featured Post

Don't Miss ATEN at InfoComm 2017!

Visit booth #2167 to see the  new ATEN VM3200 32 x 32 Modular Matrix Switch. Other highlights include the VE8950 4K HDMI Over IP Extender, VS1912 12-Port DP Video Wall Media Player  and VK2100 ATEN Control System. Register now with Free Pass Code ATEN288!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
It started not too long ago. It was at first annoying. My keystrokes seemed to be randomly generated, not the ones I typed on the keyboard. For some reason this only happened in certain applications (especially browsers such as IE11, Firefox and Chr…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question