目录
一、参考:
1、运行代码:Opencv2.4学习::摄像头读取&&视频写入:
1、opencv读取视频,摄像头,保存视频代码 (2012-10-18 21:25:26)
1、Opencv中VideoWriter详解:
1、OpenCV打开相机
一、配置环境:
1、参考:
一、OpenCV中CV_FOURCC可以获取的编码格式
一、自己写的:打开和保存相机视频
一、问题:
1、再MFC中使用while循环会导致:MFC的按键检测没有反应了,总之是while问题,所以可以做MFC定时器来存储图片
①、CPP的OpenOrCloseCameraVideo函数中
①、定时器中
①、头文件中
1、opencv的dll文件再Release、Debug模式下是不同设置的
①、报错:消息
①、Release模式下:将带d的lib文件全部删除
①、Debug模式下的lib文件:因为d结尾的lib文件再前面所以没有d结尾的lib文件不会影响到它,可以全部把添加进入
1、相机能打开,但是图片框是灰色的:答:缺少了等待一会儿的代码
1、问题:相机框内容总是灰色的
https://blog.csdn.net/dieju8330/article/details/82388281
http://blog.sina.com.cn/s/blog_5d1476580101aekj.html
https://blog.csdn.net/LYKymy/article/details/95066868
#include
using namespace cv;
int main()
{
//1.从摄像头读入视频
VideoCapture cap(0);
//2.循环显示每一帧
while (1)
{
Mat cam;
cap >> cam;//获取当前帧图像
imshow("相机",cam);//显示当前帧图像
waitKey(30);//延时30秒
}
return 0;
}
https://www.jb51.net/article/128824.htm
CV_FOURCC('P', 'I', 'M', '1') = MPEG-1 codec
CV_FOURCC('M', 'J', 'P', 'G') = motion-jpeg codec
CV_FOURCC('M', 'P', '4', '2') = MPEG-4.2 codec
CV_FOURCC('D', 'I', 'V', '3') = MPEG-4.3 codec
CV_FOURCC('D', 'I', 'V', 'X') = MPEG-4 codec
CV_FOURCC('U', '2', '6', '3') = H263 codec
CV_FOURCC('I', '2', '6', '3') = H263I codec
CV_FOURCC('F', 'L', 'V', '1') = FLV1 codec
OpenCV中通过CV_FOURCC生成指定编码器的代号,其中只用过PIM1这个不压缩的格式。对OpenCV读取视频支持的格式有很多疑问,用其他编码器生成的视频无法再用CvCapture读入(OpenCV 1.1版本),只能用未压缩的版本,不知道应该怎样解决
bool COpencvTestDlg::OpenAndSaveVideo()
{
//定义VideoCapture对象选择摄像头
VideoCapture capture(0);
//判断是否出错
if (!capture.isOpened())
{
return false;
}
//获取视频相关信息---分辨率(宽、高)
double frameHeight = capture.get(CV_CAP_PROP_FRAME_HEIGHT);
double frameWidth = capture.get(CV_CAP_PROP_FRAME_WIDTH);
//定义writer对象
VideoWriter outputVideo;
outputVideo.open("TestVideo.avi", CV_FOURCC('M', 'J', 'P', 'G'), 25.0, Size(frameWidth, frameHeight), true);
//判断open writer对象是否出错
if (!outputVideo.isOpened())
{
return false;
}
//循环读取一帧
Mat frameImg;
long nCount = 1;
while (1)
{
//输出当前帧数
cout << "Current frame" << nCount << endl;
capture >> frameImg;
//判断是否读完
if (!frameImg.empty())
{
imshow("frame", frameImg);
}
else
{
break;
}
outputVideo << frameImg;//将该帧写入文件
nCount++;
//按Q退出
if (char(waitKey(40) == 'q'))
{
break;
}
}
cv::destroyWindow("frame");//窗口一定要关闭,否则结束时候会出现断点
capture.release();
frameImg.release();
outputVideo.release();
return true;
}
有些变量是写在了配置文件中,参考前面不再赘述
因为Release附加依赖项也是使用了d结尾的lib文件,所以导致出现了报错
opencv_calib3d2410.lib
opencv_contrib2410.lib
opencv_core2410.lib
opencv_features2d2410.lib
opencv_flann2410.lib
opencv_gpu2410.lib
opencv_highgui2410.lib
opencv_imgproc2410.lib
opencv_legacy2410.lib
opencv_ml2410.lib
opencv_nonfree2410.lib
opencv_objdetect2410.lib
opencv_ocl2410.lib
opencv_photo2410.lib
opencv_stitching2410.lib
opencv_superres2410.lib
opencv_ts2410.lib
opencv_video2410.lib
opencv_videostab2410.lib
opencv_calib3d2410d.lib
opencv_contrib2410d.lib
opencv_core2410d.lib
opencv_features2d2410d.lib
opencv_flann2410d.lib
opencv_gpu2410d.lib
opencv_highgui2410d.lib
opencv_imgproc2410d.lib
opencv_legacy2410d.lib
opencv_ml2410d.lib
opencv_nonfree2410d.lib
opencv_objdetect2410d.lib
opencv_ocl2410d.lib
opencv_photo2410d.lib
opencv_stitching2410d.lib
opencv_superres2410d.lib
opencv_video2410d.lib
opencv_videostab2410d.lib
opencv_calib3d2410.lib
opencv_contrib2410.lib
opencv_core2410.lib
opencv_features2d2410.lib
opencv_flann2410.lib
opencv_gpu2410.lib
opencv_highgui2410.lib
opencv_imgproc2410.lib
opencv_legacy2410.lib
opencv_ml2410.lib
opencv_nonfree2410.lib
opencv_objdetect2410.lib
opencv_ocl2410.lib
opencv_photo2410.lib
opencv_stitching2410.lib
opencv_superres2410.lib
opencv_ts2410.lib
opencv_video2410.lib
opencv_videostab2410.lib
解决方法:使用release运行就有了画面