Resizing VideoCapture window on Debian Linux [Picture & Code Included]
Hey I have been struggling getting this sample code to work:
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
int main(int argc, const char** argv)
{
//create the cascade classifier object used for the face detection
CascadeClassifier face_cascade;
//use the haarcascade_frontalface_alt.xml library
face_cascade.load("../opencv/data/haarcascades/haarcascade_frontalface_alt.xml");
//setup video capture device and link it to the first capture device
VideoCapture captureDevice;
captureDevice.open(0);
//setup image files used in the capture process
Mat captureFrame;
Mat grayscaleFrame;
//create a window to present the results
namedWindow("outputCapture", 1);
//create a loop to capture and find faces
while(true)
{
//capture a new image frame
captureDevice>>captureFrame;
//convert captured image to gray scale and equalize
cvtColor(captureFrame, grayscaleFrame, CV_BGR2GRAY);
equalizeHist(grayscaleFrame, grayscaleFrame);
//create a vector array to store the face found
std::vector<Rect> faces;
//find faces and store them in the vector array
face_cascade.detectMultiScale(grayscaleFrame, faces, 1.1, 3, CV_HAAR_FIND_BIGGEST_OBJECT|CV_HAAR_SCALE_IMAGE, Size(30,30));
//draw a rectangle for all found faces in the vector array on the original image
for(int i = 0; i < faces.size(); i++)
{
Point pt1(faces[i].x + faces[i].width, faces[i].y + faces[i].height);
Point pt2(faces[i].x, faces[i].y);
rectangle(captureFrame, pt1, pt2, cvScalar(0, 255, 0, 0), 1, 8, 0);
}
//print the output
imshow("outputCapture", captureFrame);
//pause for 33ms
waitKey(33);
}
return 0;
}
And it finally is getting input from my camera, but now 95% of the image appears as green and I have no clue why:
If I move my hand I can see it update the frames as it should in the top part of the screen (those are my fingers so I know it is in fact getting images from the camera), just no idea why it's all green.
One thing I do notice is that if I set the video mode to MJPG at 10fps and then run the sample code, it resets it to YUYV at 30fps after running it. So maybe this is part of the problem because the fps is too high for it to handle? Just an idea.
UPDATE: After changing the fps settings in the code it now shows the image but is incredibly slow. I am trying to set the frame size to be lower to reduce overloading the processor:
captureDevice.set(CV_CAP_PROP_FPS, 5);
captureDevice.set(CV_CAP_PROP_FRAME_WIDTH, 320);
captureDevice.set(CV_CAP_PROP_FRAME_HEIGHT, 240);
but this isn't working, the screen resolution stays the same. It looks like this bug was never resolved: http://code.opencv.org/issues/142 and here: http://stackoverflow.com/questions/14...
Basically the same problem of changing resolution I am having. I see there is a hack I guess I can try. Too bad the functionality is a bit broken in OpenCV right now for some things, but it's still amazing to have all this utility without having to code from scratch!
On windows with a logitech C270 your lines are goods.
May be you can check return value.
Well I went into the default file cap_v4l.cpp and changed the default settings to be 320x240 and I now see the window initially pop up small, and then resize itself to be 640x480. However, you may be right that it will get a resolution of 320x240 even though it appears larger.
Checking when it gets resized though could clue me in on where in the code it's doing this. It's definitely not a straight forward problem. From what I read, the issue is that the video settings are modified by the CV_CAP_PROP values, and not pictures that it grabs. On a positive note, the massive lag I was having has been cut down to about 0.5s now that I downgraded from openCV 3.0 to 2.4.9.1 which is preferred for the Debian Linux build.
UPDATE: I did check and it confirmed my suspicion (and I think yours) that the resolution was not ever changing in the first place. It prints out "640" and "480" when I use the get(CV_CAP_PROP_FRAME_WIDTH) and height commands. So I guess it is correct that there is a bug that doesn't address image capturing.
May be you should try this program before posting a bug and try with an another webcam