|
楼主 |
发表于 2018-5-22 16:16:18
|
显示全部楼层
#include "stdafx.h"
#include <time.h>
#include <windows.h>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
Mat Srcimg, Grayimg, dstimg,c;
Mat a; // Canny 边缘检测相关变量
int b = 1; //同上
string imgPath="这个网址发不上去";
/*FileStorage fsWrite;
string FilePath = "mode.yaml";*/
static void on_Canny(int, void*);
int _tmain(int argc, _TCHAR* argv[])
{
/*bool n =0;*/
VideoCapture capture(imgPath); //调用摄像头
if (!capture.isOpened())
{
printf("can't open capture\n");
waitKey(0);
getchar();
return -1;
}
else
{
printf("you can open this!\n");
}
namedWindow("效果图",1);
capture >> c;
imshow("效果图", c);
while (1)
{
capture >> Srcimg; //逐帧显示,一直循环
imshow("原图!\n", Srcimg);
dstimg.create(Srcimg.size(), Srcimg.type()); //建立一个和Srcimg一样大小,一样类型的矩阵dstimg
cvtColor(Srcimg, Grayimg, COLOR_BGR2GRAY); //将图像转换为灰度图
//namedWindow("效果图",WINDOW_AUTOSIZE);
createTrackbar("参数值:", "效果图 Canny边缘检测", &b, 120, on_Canny);//建立一个滑动条
on_Canny(0, 0);
if (waitKey(30) == 27) //按键esc退出
{
break;
}
/*if ()
{
break;
}*/
}
return 0;
}
void on_Canny(int, void*) //回掉函数
{
blur(Grayimg, a, Size(2, 3));
Canny(a, a, b, b * 5, 3);
dstimg = Scalar::all(0);
Srcimg.copyTo(dstimg, a);
imshow("效果图 Canny边缘检测", dstimg);
}
|
|