📄 contour2.dpr
字号:
program Contour2;
uses
Forms,
IPL in 'Ipl.pas',
OpenCV in 'OpenCV.pas',
highGui in 'highGui.pas';
{$R *.res}
const w = 500 ;
var imgA,imgB,img : pIplImage;
box : CvBox2D ;
storage : pcvMemStorage;
contours,Approx_contours : pCvSeq;
res : integer;
cS : cvSize ;
i,j : integer;
levels : integer = 3;
rect :cvRect;
pt : array [0..3] of CvPoint2D32f;
procedure on_trackbar( pos:integer);
var cnt_img : pIplImage;
_contours : pCvSeq;
_levels : integeR;
begin
cnt_img := cvCreateImage( cvSize_(w,w), 8, 3 );
_contours := contours;
_levels := levels - 3;
if( _levels <= 0 )then // get to the nearest face to make it look more funny
_contours := _contours.h_next.h_next.h_next;
cvZero( cnt_img );
rect := cvBoundingRect( contours, 0);
cvDrawContours( cnt_img, _contours, CV_RGB(255,0,0), CV_RGB(0,255,0), _levels, 3, CV_AA, cvPoint_(0,0) );
cvRectangle( cnt_img, cvPoint_(rect.x,rect.y), cvPoint_( rect.x+rect.width,rect.y+rect.height), CV_RGB( 255, 0, 0), 2, 8, 0);
box := cvMinAreaRect2( contours, storage);
cvBoxPoints( box, pt);
cvLine( imgB, cvPointFrom32f_( pt[0]), cvPointFrom32f_( pt[1]), CV_RGB( 255, 0, 0), 2, 8, 0);
cvLine( imgB, cvPointFrom32f_( pt[1]), cvPointFrom32f_( pt[2]), CV_RGB( 255, 0, 0), 2, 8, 0);
cvLine( imgB, cvPointFrom32f_( pt[2]), cvPointFrom32f_( pt[3]), CV_RGB( 255, 0, 0), 2, 8, 0);
cvLine( imgB, cvPointFrom32f_( pt[3]), cvPointFrom32f_( pt[0]), CV_RGB( 255, 0, 0), 2, 8, 0);
cvShowImage( 'contours', cnt_img );
cvReleaseImage( cnt_img );
end;
var dx,dy : integer;
white , black : CvScalar;
angle : double;
begin
imgA := cvLoadImage( 'image_sample16.bmp', -1);
imgB := cvCreateImage( cvSize_(imgA.Width,imgA.Height), 8, 3 );
cvZero( imgB );
// cvCvtColor( imgA, imgB, CV_GRAY2BGR);
cvNamedWindow( 'image', 1 );
cvShowImage( 'image', imgA );
storage := cvCreateMemStorage(0);
cvFindContours( imgA, storage, @contours, sizeof(CvContour),
CV_RETR_LIST, CV_CHAIN_APPROX_NONE, cvPoint_(0,0) );
//--- Esta funcion no esta Andando
// Approx_contours := cvApproxPoly( @contours, sizeof(CvContour), storage, 0, 10.0, 1 );
cvDrawContours( imgB, contours, CV_RGB(255,0,0), CV_RGB(0,255,0), 7, 3, CV_AA, cvPoint_(0,0) );
rect := cvBoundingRect( contours, 0);
cvRectangle( imgB, cvPoint_(rect.x,rect.y), cvPoint_( rect.x+rect.width,rect.y+rect.height), CV_RGB( 255, 0, 0), 2, 8, 0);
cvNamedWindow( 'contours', 1 );
cvCreateTrackbar( 'levels+3', 'contours', @levels, 7, on_trackbar );
on_trackbar(4);
cvWaitKey(0);
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -