opencv对摄像头采集视频的几种变换
2014-04-15 19:49
513 查看
#include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <stdio.h> #include <stdlib.h> #include <iostream> using namespace cv; using namespace std; Mat Sobel(Mat src);//Sobel边缘检测; Mat Laplace(Mat src);//拉普拉斯边缘检测; Mat Threshold(Mat src);//改变阈值 void threshold(int , void*);//改变阈值的回调函数 int threshold_type = 0;//阈值操作类型; int threshold_value = 0;//阈值 int const max_type = 3; int const max_value = 255; int const max_binvalue = 255; Mat thresh_temp,thresh_dst; int main(){ VideoCapture cap(0); if(!cap.isOpened()){ cout<<"摄像头未能打开"<<endl; } namedWindow("Video"); namedWindow("Sobel"); namedWindow("Laplace"); namedWindow("Threshold"); while(true){ Mat frame; cap>>frame; if(cap.isOpened() && (char)waitKey(1)!='q'){ imshow("Video",frame); imshow("Sobel",Sobel(frame)); imshow("Laplace",Laplace(frame)); imshow("Threshold",Threshold(frame)); } else break; } return 0; } Mat Sobel(Mat src){ Mat dst,temp,abs_dst; cvtColor(src,temp,CV_RGB2GRAY); Sobel(temp,dst,CV_16S,0,1,3,1,0,BORDER_DEFAULT); convertScaleAbs(dst,abs_dst); return abs_dst; } Mat Laplace(Mat src){ Mat dst,temp,abs_dst; cvtColor(src,temp,CV_RGB2GRAY); Laplacian(temp,dst,CV_16S,3,1,0,BORDER_DEFAULT); convertScaleAbs(dst,abs_dst); return abs_dst; } Mat Threshold(Mat src){ cvtColor(src,thresh_temp,CV_RGB2GRAY); createTrackbar("ThresholdType","Threshold",&threshold_type,max_type,threshold); createTrackbar("ThresholdValue","Threshold",&threshold_value,max_value,threshold); threshold(0,0); return thresh_dst; } void threshold(int,void*){ threshold(thresh_temp,thresh_dst,threshold_value,255,threshold_type); }具有一定的可玩性。
相关文章推荐
- Qt+OpenCV移植到arm上采集摄像头视频 请注意
- 用OpenCV在MFC Dialog中Picture控件上显示摄像头采集实时视频
- opencv采集视频/摄像头数据并保存
- opencv摄像头视频采集(Windows系统)
- opencv3 采集摄像头的画面canny化,或者读取视频
- OpenCV摄像头视频数据采集与RTSP和RTMP直播
- 摄像头、视频采集和摄像设备图像质量判断的几种简单有效目测方法
- Python+OpenCV采集本地摄像头的视频
- 【2012年终总结】之二 opencv + ds采集摄像头视频 GDI点点滴滴
- 海康威视多摄像头视频实时采集——OpenCV显示
- 【2012年终总结】之一 opencv + ds采集摄像头视频 MFC点点滴滴
- 【OpenCV学习】摄像头采集视频
- 【2012年终总结】之三 opencv + ds采集摄像头视频 简易截图工具
- 【2012年终总结】之一 opencv + ds采集摄像头视频 MFC点点滴滴
- Qt5.3里使用OpenCV库采集摄像头图像保存为图片和视频
- OpenCV学习——摄像头采集视频
- Qt开发:Qt+OpenCV在(Linux平台)PC上采集摄像头视频(源码奉送)
- opencv利用摄像头抓取视频方法-ubuntu
- Qt环境下利用OpenCV采集摄像头图像并保存
- opencv x64 vs2010 下打开摄像头录制视频写成avi(代码为转载)