Outline
Topic Requirements |
Program code |
Result picture |
Homilies Miao DAO |
Title Requirements:
Excellent code reference:
1#include <iostream>2#include <cv.h>3#include 4#include <cxcore.h>5 6 using namespacestd;7 ConstCvsize size = Cvsize ( $, $);8 Const intAperture[] = {3,5,9, One, -, -};9 intMain ()Ten { OneIplimage *src = cvcreateimage (Size,8,1); A Cvzero (SRC); - cvline (src - //, Cvpoint (0,size.height-1) the //, Cvpoint (size.width-1, 0) -, Cvpoint (0,0) -, Cvpoint (Size.width-1, Size.Height-1) -, Cv_rgb (255,255,255) +,3 - ); +Cvshowimage ("src", SRC); A atIplimage *deriv_x = Cvcreateimage (size,ipl_depth_32f,1); -Iplimage *deriv_y = Cvcreateimage (size,ipl_depth_32f,1); -Iplimage *magnitude = Cvcreateimage (size,ipl_depth_32f,1); -Iplimage *angle = Cvcreateimage (size,ipl_depth_32f,1); -Iplimage *mask = Cvcreateimage (size,ipl_depth_8u,1); - for(intI=0;i<sizeof(Aperture)/sizeof(aperture[0]);++i) { inCvsobel (src,deriv_x,1,0, Aperture[i]); -Cvsobel (Src,deriv_y,0,1, Aperture[i]); to +Cvcarttopolar (Deriv_x,deriv_y,magnitude,angle,1); - theCvsave ("X.xml", deriv_x); *Cvsave ("Y.xml", deriv_y); $Cvsave ("Magnitude.xml", magnitude);Panax NotoginsengCvsave ("Angle.xml", angle); - the DoubleMax_mag, Min_mag, Max_angle, Min_angle; +Cvminmaxloc (magnitude,&min_mag,&max_mag); ACvminmaxloc (angle,&min_angle,&max_angle); thecout<<"Magnitude:max ="<<max_mag<<"min ="<<min_mag<<Endl; +cout<<"Angle:max ="<<max_angle<<"min ="<<min_angle<<Endl; - $Cvcmps (magnitude,max_mag*3/4, MASK,CV_CMP_GT); $Cvshowimage ("Mask", mask); - -Cvscalar scalar =Cvavg (angle,mask); thecout<<"aperture ="<<aperture[i]<<", line angle ="<<scalar.val[0]<<Endl; - Cvwaitkey ();Wuyi } theCvreleaseimage (&src); -Cvreleaseimage (&magnitude); WuCvreleaseimage (&angle); -Cvreleaseimage (&mask); About cvdestroyallwindows (); $ -}
View Code
from: Learning OpenCV Sixth Exercise 5, using the X, Y hierarchy to find the angle of a unique line within an image
Program code:
Result Picture:
Homilies Miao DAO:
"Exercise 6.5"