问题描述:
使用简单的代码,我可以访问我的内部摄像头网络摄像头并更改分辨率。因此,使用默认分辨率和预定义分辨率(例如,从 640x480 到 320x240,使用 cap.set(CV_CAP_PROP_FRAME_WIDTH,320) 和 FRAME_HEIGHT, 240))显示帧 - 两者都可以正常工作。
使用相同的代码稍作调整,使其适用于 Ximea 相机 (VideoCapture cap(CV_CAP_XIAPI)),适用于默认分辨率。它是一个 MU9PC_MH,默认分辨率为 2592x1944,因此 648 x486 是所需的较低分辨率。
对于手动设置的分辨率,显示的窗口/抓取的帧具有默认分辨率(2592x1944)的大小,并在这个巨大的显示器中显示捕获的较低像素量,因此上五分之一充满了困惑的像素,其余的窗户是黑色的。
这种效果发生在带有 VideoCapture 和 Mat 的 C++ 以及 C CvCaptureFromCAM 和 IplImage* 中。
当我使用设置标志 CV_CAP_PROP_XI_DOWNSAMPLING 时,我可以看到像素顺序正确的输出图像,但显示帧仍然具有默认的高分辨率,并且输出图像显示多次(该因素取决于我的因素用于下采样)。
我什至无法将 Mat 或 IplImage 强制为预定义的大小,因为随后会发生断言错误或访问冲突(Mat image(XRES, YRES, CV_8UC3, Scalar(0,0,255)) (frame = cvCreateImage(cvSize (XRES, YRES), IPL_DEPTH_8U,3);. 我通过 frame.type() 检查了输出是 CV_8UC3
我想要的是一个 648x486 的 Ximea 相机输出,显示在相同尺寸的(理想情况下)垫子中。有没有人遇到过同样的问题?可能是由于我对工业相机配置/开发缺乏了解,但感谢您提供任何帮助。
情况:Windows 7(x64) Visual Studio Professional 2012 OpenCV 版本 2.4.10 为 x86 编译并检查了以下标志: WITH_XIMEA 和 WITH_OPENGL x86 中的简单 VS2012 项目(发布和调试),用于相机流式传输和在窗口中显示相机帧。
简单代码片段(不是我的,从 opencv 教程和 ximea 复制):C++ 风格:
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char **argv) {
VideoCapture cap(0); // open the default camera
//VideoCapture cap(CV_CAP_XIAPI);
if(!cap.isOpened()) // check if we succeeded
return -1;
cout<<" "<<cap.get(CV_CAP_PROP_FRAME_WIDTH)<<" "<<cap.get(CV_CAP_PROP_FRAME_HEIGHT)<<endl; //output: 640, 480
cap.set(CV_CAP_PROP_FRAME_WIDTH,XRES);
cap.set(CV_CAP_PROP_FRAME_HEIGHT,YRES);
cout<<" "<<cap.get(CV_CAP_PROP_FRAME_WIDTH)<<" "<<cap.get(CV_CAP_PROP_FRAME_HEIGHT)<<endl; //output: 320, 240
for(;;)
{
Mat frame;
cap >> frame; // get a new frame from camera
imshow("camera frame", frame);
if(waitKey(30) == 27) //wait for 'esc' key press
{
cout << "esc key is pressed by user" << endl;
break;
}
}
return 0;}
#include "cv.h"
#include "highgui.h"
#include <stdio.h>
#include <iostream>
using namespace cv;
using namespace std;
// A Simple Camera Capture Framework
int main()
{
CvCapture* capture = cvCaptureFromCAM( CV_CAP_XIAPI );
if ( !capture ) {
fprintf( stderr, "ERROR: capture is NULL \n" );
getchar();
return -1;
}
cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH, 648 );
cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT, 486 );
// Create a window in which the captured images will be presented
cvNamedWindow( "mywindow", CV_WINDOW_AUTOSIZE );
// Show the image captured from the camera in the window and repeat
while ( 1 ) {
// Get one frame
IplImage* frame = cvQueryFrame( capture );
cout<<cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH); //output: 648
cout<<cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT); //output: 486
cout<<frame->height<<frame->width<<endl; //output: 1944, 2592
if ( !frame ) {
fprintf( stderr, "ERROR: frame is null...\n" );
getchar();
break;
}
cvShowImage( "mywindow", frame );
// Do not release the frame!
//If ESC key pressed, Key=0x10001B under OpenCV 0.9.7(linux version),
//remove higher bits using AND operator
if ( (cvWaitKey(10) & 255) == 27 ) break;
}
// Release the capture device housekeeping
cvReleaseCapture( &capture );
cvDestroyWindow( "mywindow" );
return 0;
}