使用 Visual Studio 的网络摄像头 2015
Webcam using Visual Studio 2015
我有 VS-15 和 OpenCV-3.1。在输出 window 上,我得到一个纯灰色的空白显示。我该如何解决?
#include <opencv2\highgui\highgui.hpp>
int main() {
cvNamedWindow("Webcam Stream", CV_WINDOW_AUTOSIZE);
CvCapture* capture = cvCreateCameraCapture(0);
IplImage* frame;
while (1) {
frame = cvQueryFrame(capture);
if (!frame) break;
cvShowImage("Streaming", frame);
char c = cvWaitKey(33);
if (c == 27) break;
}
cvReleaseCapture(&capture);
cvDestroyWindow("Example");
return 0;
}
不知道为什么它不起作用。但我设法从 here 中找到了另一个代码。此新代码不显示镜像,因此视图被横向翻转。但它有效。
要对其进行编辑以使图像不翻转,请将 while 循环替换为:
while (1)
{
Mat frame;
Mat flipped; //***added new line
bool bSuccess = cam.read(frame); // read a new frame from video
if (!bSuccess) //if not success, break loop
{
cout << "Cannot read a frame from video stream" << endl;
break;
}
cv::flip(frame, flipped, 1); //***added new line
imshow("MyVideo", flipped); //***editted line
if (waitKey(30) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
{
cout << "esc key is pressed by user" << endl;
break;
}
}
我有 VS-15 和 OpenCV-3.1。在输出 window 上,我得到一个纯灰色的空白显示。我该如何解决?
#include <opencv2\highgui\highgui.hpp>
int main() {
cvNamedWindow("Webcam Stream", CV_WINDOW_AUTOSIZE);
CvCapture* capture = cvCreateCameraCapture(0);
IplImage* frame;
while (1) {
frame = cvQueryFrame(capture);
if (!frame) break;
cvShowImage("Streaming", frame);
char c = cvWaitKey(33);
if (c == 27) break;
}
cvReleaseCapture(&capture);
cvDestroyWindow("Example");
return 0;
}
不知道为什么它不起作用。但我设法从 here 中找到了另一个代码。此新代码不显示镜像,因此视图被横向翻转。但它有效。
要对其进行编辑以使图像不翻转,请将 while 循环替换为:
while (1)
{
Mat frame;
Mat flipped; //***added new line
bool bSuccess = cam.read(frame); // read a new frame from video
if (!bSuccess) //if not success, break loop
{
cout << "Cannot read a frame from video stream" << endl;
break;
}
cv::flip(frame, flipped, 1); //***added new line
imshow("MyVideo", flipped); //***editted line
if (waitKey(30) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
{
cout << "esc key is pressed by user" << endl;
break;
}
}