Outline
Topic Requirements |
Program code |
Result picture |
Homilies Miao DAO |
Title Requirements:
Can be divided into nuclear. Create a 3*3 Gaussian nucleus using rows [(1/16,2/16,1/16), (2/16,4/16,2/16), (1/16,2/16,1/16)] and at the intermediate reference points.
A. Run this core on a pair of images and display the result.
B, now create a reference point in the center of the two cores: one "crossover" (1/4,2/4,1/4), the other descending (1/4,2/4,1/4). Load the same original image, use CVFILTER2D () to do two convolution of the image, first with the first one-dimensional core, and second with the second one-dimensional nucleus. Describe the results.
For the description in question B, tentatively understood as one-dimensional cores of three columns and three rows in a row
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\\rca_indian_head_test_pattern.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); to +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 + { AImage_gray =cvcloneimage (image_resource); the } + -Cvshowimage ("Original Image", Image_gray); $ $ //---------------------------A:--------------------------------/: - - ///: the //using the following form, the result is wrong, because the result of 1/16 is 0.000000000, it must be this way, it's not as good as the following - //float Matdata[9] = {Wuyi //( 1/16), (2/16), (1/16) , the //( 2/16), (4/16), (2/16) , - //( 1/16), (2/16), (1/16) Wu //}; - ///. About $ floatAtomvalue = (float)1/ (float) -; - floatMultiplier_2 =2.0f; - floatMultiplier_4 =4.0f; - A floatmatdata[9] = { +Atomvalue, atomvalue*multiplier_2, Atomvalue, theAtomvalue * multiplier_2, Atomvalue * multiplier_4, Atomvalue *multiplier_2, -Atomvalue, Atomvalue * multiplier_2/Atomvalue $ }; the theCvmat mat = Cvmat (3,3, CV_32FC1, matdata); the theIplimage * Image_result_a =cvcloneimage (image_gray); - Cvzero (image_result_a); in theCvfilter2d (Image_gray, Image_result_a, &mat); theCvshowimage ("Topic _a", image_result_a); About the //---------------------------A:--------------------------------/. the the //---------------------------B:--------------------------------/: + -Iplimage *image_result_b =cvcloneimage (image_gray); the Cvzero (image_result_b);Bayi theAtomvalue = (float)1/ (float)4; the -Cvmat *mat_b = Cvcreatemat (1,3, CV_32FC1); -Cvmset (Mat_b,0,0, atomvalue); theCvmset (Mat_b,0,1, Atomvalue *multiplier_2); theCvmset (Mat_b,0,2, atomvalue); the thecvmat* mat_b_2 = Cvcreatemat (3,1, CV_32FC1); -Cvmset (mat_b_2,0,0, atomvalue); theCvmset (mat_b_2,1,0, Atomvalue *2); theCvmset (mat_b_2,2,0, atomvalue); the 94 cvfilter2d (Image_gray, Image_result_b, mat_b); the cvfilter2d (Image_result_b, Image_result_b, mat_b_2); the theCvshowimage ("Topic _b", image_result_b);98 About //---------------------------B:--------------------------------/. - 101Cvwaitkey (0);102 103Cvreleaseimage (&image_resource);104Cvreleaseimage (&image_result_a); theCvreleaseimage (&image_result_b);106Cvreleasemat (&mat_b);107Cvreleasemat (&mat_b_2);108 109Cvdestroywindow ("Original Image"); theCvdestroywindow ("Topic _a");111Cvdestroywindow ("Topic _b"); the 113 return 0; the}
Result Picture:
Homilies Miao DAO:
①int Type Division If you think of float, you must advance strong, for example: float atomvalue = (float)1 /(float) ;
② when using cvfliter2d, if you are using a and, the value of anchor can only use the default value, that is Cvpoint ( -1,-1), if you want to customize, will error, but when testing the 3x3 kernel, the custom anchor run normally, such as the code in part B of the Cvfilter2d (Image_gray, Image_result_b, mat_b); If you change to cvfilter2d (Image_gray, Image_result_b, Mat_b,cvpoint (0,2)) , the error
"Exercise 6.2" cvfilter2d and 3x3 Gaussian nuclei, cvfilter2d when using one-dimensional nuclei anchor considerations, float Multiplication Division considerations