opencv读取摄像头数据,电脑自带摄像头灯亮,图像却一片灰色

carpediem_ 2015-11-21 02:19:05
win10,opencv,vs2015环境下,抄书上的代码,如下


int main(int argc, char** argv)
{
cvNamedWindow("Example2", CV_WINDOW_AUTOSIZE);
CvCapture* capture;
if (argc == 1) {
capture = cvCreateCameraCapture(0);
}
else {
capture = cvCreateFileCapture(argv[1]);
}
assert(capture != NULL);
IplImage* frame;
while (1) {
frame = cvQueryFrame(capture);
if (!frame)break;
cvShowImage("Example2", frame);
char c = cvWaitKey(33);
if (c == 27)break;
}
cvReleaseCapture(&capture);
cvDestroyWindow("Example2");
}



求助。。试了论坛里面各位的代码,代码debug和摄像头均正常,就是无法显示图像。
...全文
4158 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
rdc01234 2018-05-15
  • 打赏
  • 举报
回复
所以你需要在后面加一句waitKey();
rdc01234 2018-05-15
  • 打赏
  • 举报
回复
来自OpenCV官网手册:http://docs.opencv.org/2.4/modules/highgui/doc/user_interface.html?highlight=waitkey Note This function(imshow) should be followed by waitKey function which displays the image for specified milliseconds. Otherwise, it won’t display the image. For example, waitKey(0) will display the window infinitely until any keypress (it is suitable for image display). waitKey(25) will display a frame for 25 ms, after which display will be automatically closed. (If you put it in a loop to read videos, it will display the video frame-by-frame)
  • 打赏
  • 举报
回复
我3.3的版本跑了你的程序,加上namedWindow("当前视频");解决了,但是是有两个窗口的,一个灰色的啥也不显示,一个正常的,如下图,有没有啥解决方法呢 ?那个灰色的窗口也不能关掉的,关掉正常的也不行 了
xungeer29 2017-12-04
  • 打赏
  • 举报
回复
我也出现这种情况了,楼主解决了吗?
qq_24580967 2017-07-24
  • 打赏
  • 举报
回复
VideoCapture cap(0);改0为-1或者1试试; 我之前是-1,改成0后,成功显示了
shiter 2017-01-07
  • 打赏
  • 举报
回复
当然是所有配置保持统一啊。。。
micky__ 2017-01-06
  • 打赏
  • 举报
回复
引用 9 楼 wangyaninglm 的回复:
估计是这样的,你的系统是64位的,你用的32位的dll和lib在跑
那该怎么办呢
赵4老师 2016-03-08
  • 打赏
  • 举报
回复
一只灰色的会飞的大母bug一直对着摄像头搔首弄姿摆pose不舍得离去?
shiter 2016-03-06
  • 打赏
  • 举报
回复
引用 10 楼 zhouthy 的回复:
摄像头是vfw型的吗?听说opencv只支持vfw的
opencv2是ffmpeg
  • 打赏
  • 举报
回复
摄像头是vfw型的吗?听说opencv只支持vfw的
shiter 2016-01-27
  • 打赏
  • 举报
回复
估计是这样的,你的系统是64位的,你用的32位的dll和lib在跑
ArthurKingYs 2016-01-26
  • 打赏
  • 举报
回复
首先安装好opencv 在按我的博客做就行了 http://blog.csdn.net/u011001084/article/details/50550799
shiter 2015-12-16
  • 打赏
  • 举报
回复
单步调试一下,你的命令行参数不一定有啊
赵4老师 2015-12-15
  • 打赏
  • 举报
回复
雾霾太大?!
corfox_liu 2015-12-15
  • 打赏
  • 举报
回复
直接把你的代码拷贝下来在我的电脑上式可以正确运行的,是不是你的哪儿配置出问题了。
geleg 2015-12-15
  • 打赏
  • 举报
回复
单步调试看一看。 另外灯亮是插电脑上,灯就亮了吗? 你的代码中只有捕捉图像的函数,没看见打开摄像头的函数。设备首先要激活才能开始采集图像。
lx624909677 2015-12-15
  • 打赏
  • 举报
回复
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>

using namespace cv;


int main()
{
	VideoCapture cap(0);
	if(!cap.isOpened())
	{
		return -1;
	}
	Mat frame;
	Mat edges;

	bool stop = false;
	while(!stop)
	{
		cap>>frame;
		cvtColor(frame, edges, CV_BGR2GRAY);
		GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
		Canny(edges, edges, 0, 30, 3);
		imshow("当前视频",edges);
		if(waitKey(30) >=0)
			stop = true;
	}
	return 0;
}
赵4老师 2015-11-23
  • 打赏
  • 举报
回复
不要抄书上,直接用OpenCV自带的例子。
carpediem_ 2015-11-22
  • 打赏
  • 举报
回复

19,469

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧