Visual studio Can';在Visual Studio上运行OpenCV代码时,不要使用内置笔记本电脑摄像头
我已经按照教程在我的东芝Satellite P755笔记本电脑上安装了OpenCV。这是我试图运行的代码:Visual studio Can';在Visual Studio上运行OpenCV代码时,不要使用内置笔记本电脑摄像头,visual-studio,opencv,visual-studio-2013,webcam,video-capture,Visual Studio,Opencv,Visual Studio 2013,Webcam,Video Capture,我已经按照教程在我的东芝Satellite P755笔记本电脑上安装了OpenCV。这是我试图运行的代码: #include <opencv\cv.h> #include <opencv\highgui.h> #include <iostream> using namespace std; using namespace cv; int main() { //Create matric to store image Mat image;
#include <opencv\cv.h>
#include <opencv\highgui.h>
#include <iostream>
using namespace std;
using namespace cv;
int main() {
//Create matric to store image
Mat image;
//initialize capture
VideoCapture cap;
cap.open(0);
//create window to show image
namedWindow("window", 1);
while (1){
// copy webcam stream to image
cap >> image;
// print image to screen
imshow("window", image);
//delay 33ms
waitKey(33);
}
}
#包括
#包括
#包括
使用名称空间std;
使用名称空间cv;
int main(){
//创建矩阵来存储图像
Mat图像;
//初始化捕获
视频捕捉帽;
上限开放(0);
//创建窗口以显示图像
namedWindow(“窗口”,1);
而(1){
//将网络摄像头流复制到图像
cap>>图像;
//将图像打印到屏幕
imshow(“窗口”,图像);
//延迟33ms
waitKey(33);
}
}
外置USB Logitech摄像头运行良好,但每当我尝试使用内置笔记本电脑摄像头运行时,就会出现以下错误。
我曾尝试重新安装摄像头驱动程序(即使很难,摄像头也能与其他应用程序完美配合),并尝试更改cap.open(0)代码>至<代码>盖打开(1)代码>(连接Logitech摄像头时)但我仍然收到相同的错误。我看到相机的蓝光亮起,但在相机窗口中没有任何实时图像,而是弹出错误消息。我尝试调试它,当我一步一步运行它(使用F10)时,错误消息不会显示,我在“相机”窗口中从相机中获得一个帧,但我无法将其打开作为主窗口,而只能在快速启动栏中将其悬停在背景上观看:
我正在运行Windows 7 64位和Visual Studio 2013 12.0.21005.1 REL.您能用VLC Order DirectShow(例如GraphStudio)打开摄像头吗?是的,我能。正如我所提到的,我的网络摄像头在任何其他应用程序(包括VLC)上都可以正常工作。您可以尝试VideoInput library吗?或者更好:如果(image.empty())继续,您可以添加一个;在imshow?之前的代码中,看起来您的相机在每次迭代中都不会提供图像,因此您必须检查是否生成了图像。