opencv视频调用(边缘,二值,灰度处理)
简单程序。。。。
此程序可对视频进行边缘,二值,灰度处理
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>
#include
using namespace cv;
Mat frame;
Mat edges;
Mat erzhi;
void huidutu() {
namedWindow(“灰度”);
cvtColor(frame, edges, CV_BGR2GRAY);
imshow(“灰度”, edges);
}
void erzhitu(int pos, void*) {
namedWindow("二值");
cvtColor(frame, edges, CV_BGR2GRAY);
threshold(edges, erzhi, pos, 255, CV_THRESH_BINARY);
imshow("二值", erzhi);
}
void bianyuan() {
namedWindow(“当前视频”);
cvtColor(frame, edges, CV_BGR2GRAY);
GaussianBlur(edges, edges, Size(7, 7), 1.5, 1.5);
Canny(edges, edges, 0, 30, 3);
imshow(“当前视频”, edges);
}
int main()
{
VideoCapture cap(0);
if (!cap.isOpened())
{
return -1;
}
bool stop = false;
while (!stop)
{
cap >> frame;
huidutu();
bianyuan();
erzhitu(120,0);
if (waitKey(30) >= 0)
stop = true;
}
return 0;
}