OpenCV:如何在 Windows 窗体应用程序中显示网络摄像头捕获?
通常我们在 opencv 窗口中显示网络摄像头或视频运动:
CvCapture* capture = cvCreateCameraCapture(0);
cvNamedWindow( "title", CV_WINDOW_AUTOSIZE );
cvMoveWindow("title",x,y);
while(1)
{
frame = cvQueryFrame( capture );
if( !frame )
{
break;
}
cvShowImage( "title", frame );
char c = cvWaitKey(33);
if( c == 27 )
{
break;
}
}
我尝试使用 pictureBox 成功地以窗口形式显示图像:
pictureBox1->Image = gcnew System::Drawing::Bitmap( image->width,image->height,image->widthStep,System::Drawing::Imaging::PixelFormat::Undefined, ( System::IntPtr ) image-> imageData);
但是当我尝试显示从视频中捕获的图像时,它不起作用,这里是来源:
CvCapture* capture = cvCreateCameraCapture(0);
while(1)
{
frame = cvQueryFrame( capture );
if( !frame )
{
break;
}
pictureBox1->Image = gcnew System::Drawing::Bitmap( frame->width,frame->height,frame->widthStep,System::Drawing::Imaging::PixelFormat::Undefined, ( System::IntPtr ) frame-> imageData);
char c = cvWaitKey(33);
if( c == 27 )
{
break;
}
}
有吗无论如何使用 Windows 窗体而不是 opencv Windows 来显示视频或网络摄像头?
或者我的代码有问题吗? 感谢您的帮助.. :)
generally we display webcam or video motion in opencv windows with :
CvCapture* capture = cvCreateCameraCapture(0);
cvNamedWindow( "title", CV_WINDOW_AUTOSIZE );
cvMoveWindow("title",x,y);
while(1)
{
frame = cvQueryFrame( capture );
if( !frame )
{
break;
}
cvShowImage( "title", frame );
char c = cvWaitKey(33);
if( c == 27 )
{
break;
}
}
i tried to use pictureBox that is successful to display image in windows form with this :
pictureBox1->Image = gcnew System::Drawing::Bitmap( image->width,image->height,image->widthStep,System::Drawing::Imaging::PixelFormat::Undefined, ( System::IntPtr ) image-> imageData);
but when im trying to display captured image from video it wont works, here is the source :
CvCapture* capture = cvCreateCameraCapture(0);
while(1)
{
frame = cvQueryFrame( capture );
if( !frame )
{
break;
}
pictureBox1->Image = gcnew System::Drawing::Bitmap( frame->width,frame->height,frame->widthStep,System::Drawing::Imaging::PixelFormat::Undefined, ( System::IntPtr ) frame-> imageData);
char c = cvWaitKey(33);
if( c == 27 )
{
break;
}
}
is there anyway to use windows form instead opencv windows to show video or webcam?
or is there something wrong with my code?
thanks for your help.. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
一条建议:使用 VideoInput 而不是 CvCapture (CvCapture 是 highgui 库的一部分,不适用于生产用途,仅用于快速测试)。是的,VideoInput 主页看起来很奇怪,但是这个库非常值得。
以下是 VideoInput 用法的快速示例(摘自 VideoInput.h 文件):
Piece of advice : use VideoInput instead of CvCapture (CvCapture is a part of highgui a library that is not intended for production use, but just for quick testing). Yes the VideoInput homepage looks strange, but the library is quite worthwhile.
Here is a quick sample for the usage of VideoInput (extracted from the VideoInput.h file):
当您从相机捕获图像时,应该知道像素格式,它很可能是 24 位 BGR 的格式。
System::Drawing::Imaging::PixelFormat::Format24bppRgb
将是最接近的格式,但您可能会得到奇怪的颜色显示。重新排列颜色分量将解决这个问题。实际上,这里有.net版本的opencv库:
http://code.google.com/p/opencvdotnet/
在这里:
http://www.emgu.com/wiki/index.php/Main_Page
希望有帮助!
The pixel format should be known when you capture images from a camera, it's very likely the format of 24-bit BGR.
System::Drawing::Imaging::PixelFormat::Format24bppRgb
will be the closest format but you might get weird color display. A re-arrange of the color component will solve this problem.Actually, there are .net version opencv library available here:
http://code.google.com/p/opencvdotnet/
and here:
http://www.emgu.com/wiki/index.php/Main_Page
Hope it helps!
我不知道你是否会喜欢这个,但是你可以使用 OpenGL 在 opencv 提供的窗口之外的其他窗口中显示视频流。 (捕获帧并将其显示在矩形上..或类似的东西..)
I don't know if you will like this, but you could use OpenGL to show the video stream in other windows than the ones provided with opencv. (Capture the frame and display it on a rectangle.. or something like that..)
您可能要考虑的另一个选择是使用 emgu。这是带有 winforms 控件的 opencv 的 .Net 包装器。
Another option you might want to consider is using emgu. This is a .Net wrapper for opencv with winforms controlls.