我尝试下面的代码使用带有openCV的摄像头捕获单个图像并保存。我运行此代码并保存图像(使用F10按钮)但是当我在调试模式下运行它时会显示输入的错误在代码中,请告诉我解决方案以及发生这种情况的原因;
#include <opencv\cv.h>
#include <opencv\highgui.h>
#include <time.h>
using namespace cv;
using namespace std;
int main()
{
// Capture the Image from the webcam
VideoCapture cap(0);
// Get the frame
Mat save_img;
while (1)
{
cap >> save_img;
time_t start_time, cur_time;
time(&start_time);
do
{
time(&cur_time);
} while ((cur_time - start_time) < 5);
if (save_img.empty())
{
std::cerr << "Something is wrong with the webcam, could not get frame." << std::endl;
}
// Save the frame into a file
imwrite("test.jpg", save_img);
char c = cvWaitKey(30);
if (c == 27) break;
}
return 0;
}
这里