我正在尝试使用sample代码通过笔记本电脑的嵌入式相机获取图像。我可以得到图像。但 imshow 语句会抛出执行访问冲突
任何人都可以帮我弄清楚原因吗?
非常感谢!
环境:Visual Studio 2015,Opencv 3.2
c ++代码:
using namespace cv;
using namespace std;
int main(int, char**)
{
Mat frame;
VideoCapture cap;
cap.open(0);
if (!cap.isOpened())
{
cerr << "ERROR, unable to open the camera\n";
return -1;
}
std::cout << "start grapping" << endl;
for (;;)
{
cap.read(frame);
if (frame.empty())
{
cerr << "ERROR, blank frame grabbed \n";
break;
}
// I added below statement to save the frame.
// check the frame from the camera.
imwrite("D:\\CapturedImage.jpg", frame);
// Below line throw Access violation executing location error
imshow("Live", frame);
}
}