Hi,
I would like to capture an image whenever my program runs. Then I ask the user if the image is okay, and if he says "no", I capture another one. But, if he says "no" for the first time, I get to see the same old first image. If he says "no" for the second time, then I see the new image. What is going on here?
#include
#include
#include
#include
#include
#include
using namespace std;
using namespace cv;
Mat mySrc;
char window_frame[] = "Input Frame";
int main()
{
VideoCapture cap(0);
cap.set(CV_CAP_PROP_FRAME_WIDTH, 1280); // Set width in pixels
cap.set(CV_CAP_PROP_FRAME_HEIGHT, 720); // Set height in pixels
string s_isPicOkay;
int int_isPicOkay = 0;
if (!cap.isOpened()) // Check if we are connected to the camera
{
cout << "Failed to connect to the camera.\n";
return -1;
}
while (!int_isPicOkay)
{
cap >> mySrc;
if (mySrc.empty()) // Check if we were able to capture an image
{
cout << "Failed to capture an image.\n";
return -1;
}
else
{
imshow(window_frame, mySrc);
waitKey(1);
cout << "Is the picture okay? (Y/N): ";
getline(cin, s_isPicOkay);
if ((s_isPicOkay == "Y") || (s_isPicOkay == "y"))
{
destroyWindow(window_frame);
int_isPicOkay = 1;
}
else if ((s_isPicOkay == "N") || (s_isPicOkay == "n"))
{
destroyWindow(window_frame);
}
}
}
cvWaitKey(0);
return 0;
}
If I capture the image twice, it works okay, but I just want to know what the problem is here.
Thank you.
↧