Different range of len captured by one webcam [closed]
I encounter a weird problem when capturing frames of my webcam. When I preview the webcam using other's application, which needs to be reverse engineered, the frame is complete: complete len's contour and normal size objects. However, in my program (see below), the frame is incomplete: the len seems to be biased and the frame is enlarged a little compared to the normal size. Fig.1 and Fig.2 shows the screenshots of the same object captured by two programs I just mentioned. (The frame resolution is 422x314)
Fig.1 Other's application's preview
Fig.2 My program's preview
My code
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main(int argc, char** argv) {
// Current frame
Mat frame;
// Capture video from the camera
int device = 1;
VideoCapture capture(device);
while (1) {
// Query for frame from camera
capture >> frame;
// Display the captured image
resize(frame, frame, Size(422, 314));
namedWindow("frame", CV_WINDOW_AUTOSIZE);
imshow("frame", frame);
char ch = waitKey(25);
if (ch == 27) break;
}
return 0;
}
The main OpenCV function employed in my code is VideoCapture capture(device)
and I resize
frame to 422x314 in order to keep same as the other's. Actually, the default resolution captured by OpenCV is 640x480 that still has problem of incomplete frame. I don't know why one webcam can produce two different ranges of len. Is that caused by the software? Perhaps not.
To go further, I use MATLAB image acquisition tool to preview the webcam in different resolutions. I surprisedly find that the two previews can be seen when choosing different resolutions! In default (written in MATLAB) resolution 352x288, the preview is same as the normal one, but in resolution like 640x480, 320x240, the preview is same as my program. So is the problem caused by the hardware?
I can't change the hardware (webcam), so how can I modify the OpenCV code to make my frame be complete and normal? Please tell me what you want to know about my webcam specification if it matters.
My working is on Windows 7, Visual Studio 2008 and OpenCV 2.4.5.