Outline
Topic Requirements |
Program code |
Result picture |
Homilies Miao DAO |
Title Requirements:
Use cvfilter2d to create a filter that detects only the 60-degree angle of a line in an image. The results are displayed. Do a partial step operation:
A, custom convolutional cores, using cvfilter2d, processing images
b, the result of a image threshold, is 60 degrees more clear line
c, corrosion of the results of B
Note:
For this problem, I understand that only a 60-degree angle of the picture is retained in order to increase the familiarity of the custom filter
There are more commonly used filter templates in the OpenCV convolution filtering cvfilter2d article to learn
Program code:
1 //OpenCVExerciseTesting.cpp: Defines the entry point of the console application. 2 //3 //d:\\work\\work_programming\\source\\image\\lena.jpg4 5 6#include"stdafx.h"7#include <cv.h>8#include 9#include <iostream>Ten One#include <opencv2/legacy/legacy.hpp> A //#pragma comment (lib, "Opencv_legacy2411.lib") - - using namespaceCV; the using namespacestd; - - //function declaration---->-->--->-->--->-->--->// - + - //<--<--<--<--<--<--<--<--<--Function Declaration// + A int_tmain (intARGC, _tchar*argv[]) at { - Const Char* Soutcefile ="d:\\work\\work_programming\\source\\image\\opencvexerciseimage\\ the 5th chapter \ \ Each angle straight. jpg"; -Iplimage * Image_resource =cvloadimage (Soutcefile, cv_load_image_unchanged); - assert (Image_resource); - -Cvnamedwindow ("Original Image",0); inCvnamedwindow ("Topic _a",0); -Cvnamedwindow ("Topic _b",0); toCvnamedwindow ("Topic _c",0); + -Iplimage * Image_gray = Cvcreateimage (Cvsize (Image_resource->width, Image_resource->height), IPL_DEPTH_8U,1); the * //before using Cvcvtcolor and cvcopy These functions, you should validate the parameters before using them. $ if(Image_resource->nchannels = =3)Panax Notoginseng { - Cvcvtcolor (Image_resource, Image_gray, Cv_rgb2gray); the } + Else A { theImage_gray =cvcloneimage (image_resource); + } - $Cvshowimage ("Original Image", Image_gray); $ - //---------------------------A:--------------------------------/: - the floatmatdata[ the] = { - 0.0f,0.0f,0.0f,0.0f,0.11f,0.7f,0.0f,Wuyi 0.0f,0.0f,0.0f,0.0f,0.4f,0.0f,0.0f, the 0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f, - 0.0f,0.0f,0.0f,0.8f,0.0f,0.0f,0.0f, Wu 0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f, - 0.0f,0.0f,0.4f,0.0f,0.0f,0.0f,0.0f, About 0.0f,0.7f,0.11f,0.0f,0.0f,0.0f,0.0f $ }; - -Cvmat mat = Cvmat (7,7, CV_32FC1, matdata); - AIplimage * Image_result_a =cvcloneimage (image_gray); + Cvzero (image_result_a); the -Cvfilter2d (Image_gray, Image_result_a, &mat); $Cvshowimage ("Topic _a", image_result_a); the the //---------------------------A:--------------------------------/. the the //---------------------------B:--------------------------------/: - inIplimage *image_threshold =cvcloneimage (image_result_a); the Cvzero (image_threshold); theCvthreshold (Image_result_a, Image_threshold,253,255, cv_thresh_binary); About theCvshowimage ("Topic _b", image_threshold); the the //---------------------------B:--------------------------------/. + - the //---------------------------C:--------------------------------/:Bayi theIplimage * Image_erode =cvcloneimage (image_threshold); the Cvzero (image_erode); -Iplconvkernel *kernel = Cvcreatestructuringelementex (3,3,0,0, cv_shape_rect); - Cverode (Image_threshold, Image_erode, kernel); the theCvshowimage ("Topic _c", Image_erode); the the //---------------------------C:--------------------------------/. - theCvwaitkey (0); the theCvreleaseimage (&image_resource);94Cvreleaseimage (&image_result_a); theCvreleaseimage (&image_threshold); theCvreleaseimage (&image_erode); the 98Cvdestroywindow ("Original Image"); AboutCvdestroywindow ("Topic _a"); -Cvdestroywindow ("Topic _b");101Cvdestroywindow ("Topic _c");102 103 return 0;104 } the
Result Picture:
Homilies Miao DAO:
① eliminate the 45-degree line compared to the time, you can matdata the first line as the following angle adjustment: 145 degrees 130 degrees 105 degrees 90 degrees 75 degrees 60 degrees 45 degrees, so increase the weight of 60 degrees and 75 degrees, you can eliminate the figure of 45 degrees of line, but the program is still used in the threshold and corrosion, The filter should also have room for adjustment
"Exercise 6.1" thresholding, corrosion, cvfilter2d, and custom filters