Gaussian Transformation
#include ...
int main(int argc, char** argv){
cv::namedWindow("Example3-in",cv::WINDOW_AUTOSIZE);
cv::namedWindow("Example3-out1",cv::WINDOW_AUTOSIZE);
cv::namedWindow("Example3-out2",cv::WINDOW_AUTOSIZE);
cv::Mat input = cv::imread(argv[1]);
cv::imshow("Example3-in",input);
cv::Mat output;
cv::GaussianBlur(input, output, cv::Size(5,5),3,3);
cv::imshow("Example3-out1",output);
cv::GaussianBlur(output, output, cv::Size(5,5),3,3);
cv::imshow("Example3-out2",output);
cv::waitKey(0);
return 0;
}
>> \source\repos\opencvtest\x64\Debug> .\opencvtest.exe 1.jpg
Blur and Downsample
int main(int argc, char** argv){
cv::Mat img1,img2;
cv::namedWindow("Example4",cv::WINDOW_AUTOSIZE);
cv::namedWindow("Example5",cv::WINDOW_AUTOSIZE);
img1 = cv::imread(argv[1]);
cv::imshow("Example4",img1);
cv::pyrDown(img1,img2);
cv::imshow("Example5",img2);
cv::waitKey(0);
return 0;
}
Canny Edge Detection
- image 单通道输入图像
- edges 单通道存储边缘的输出图像
- threshold1 第一个阈值
- threshold2 第二个阈值
- aperture_size Sobel 算子内核大小
函数 cvCanny 采用 CANNY 算法发现输入图像的边缘而且在输出图像中标识这些边缘。threshold1和threshold2当中的小阈值用来控制边缘连接,大的阈值用来控制强边缘的初始分割。
int main(int argc, char** argv){
cv::Mat img_rgb, img_gry, img_cny;
cv::namedWindow("Example Gray",cv::WINDOW_AUTOSIZE);
cv::namedWindow("Example Canny",cv::WINDOW_AUTOSIZE);
img_rgb = cv::imread(argv[1]);
cv::cvtColor(img_rgb, img_gry, cv::COLOR_BGR2GRAY);
cv::imshow("Example Gray", img_gry);
cv::Canny(img_gry,img_cny,10,500,3,true);
cv::imshow("Example Canny", img_cny);
cv::waitKey(0);
return 0;
}
Canny with Double pyrDown
int main(int argc, char** argv){
cv::Mat img_rgb, img_gry, img_pyr, img_cny;
cv::namedWindow("Example7",cv::WINDOW_AUTOSIZE);
cv::namedWindow("Example Canny with double pyrDown",cv::WINDOW_AUTOSIZE);
img_rgb = cv::imread(argv[1]);
cv::imshow("Example7",img_rgb);
cv::cvtColor(img_rgb, img_gry, cv::COLOR_BGR2GRAY);
cv::pyrDown(img_gry,img_pyr);
cv::pyrDown(img_pyr,img_pyr);
cv::Canny(img_pyr,img_cny,10,100,3,true);
cv::imshow("Example Canny with double pyrDown", img_cny);
cv::waitKey(0);
return 0;
}
Catch Ya!
int main(int argc, char** argv){
namedWindow("Example8: Catch Ya!",cv::WINDOW_AUTOSIZE);
VideoCapture VideoStream(CAP_DSHOW);
if (!VideoStream.isOpened()) {
cout << "Error: Cannot open video stream from camera" << endl;
return 1;
}
Mat image;
while(true){
VideoStream.read(image);
if (image.rows <= 0 || image.cols <= 0) {
cout << "Camera did not grap the image" << endl;
}
imshow("Example8: Catch Ya!",image);
char c = (char)cv::waitKey(16.67);
if (c == 27)
break;
}
return 0;
}
VideoStream可以换成VideoCapture类,效果一样。
当然,还有些阴间玩意:
int main(int argc, char** argv){
cv::namedWindow("Example8: Catch Ya!",cv::WINDOW_AUTOSIZE);
cv::VideoCapture cap;
if(argc==1)
cap.open(CAP_DSHOW);
else
cap.open(argv[1]);
if(!cap.isOpened())
std::cerr << "No camera!" << std::endl;
Mat image,img_pyr,img_gry,img_cny;
while(true){
cap.read(image);
cv::cvtColor(image,img_gry,cv::COLOR_BGR2GRAY);
cv::pyrDown(img_gry, img_pyr);
cv::Canny(img_gry,img_cny,10,100,3,true);
imshow("Example8: Catch Ya!",img_cny);
char c = (char)cv::waitKey(16.67);
if (c == 27)
break;
}
return -1;
}
不想放截图了,其实就是DownSampling & Canny Edge Detection视频.