contours4.dpr

来自「Delphi版本的OpenCV头文件库(以及诸多实例)」· DPR 代码 · 共 52 行

DPR
52
字号
program Contours4;
uses
  Forms,
  IPL in '..\Ipl.pas',
  OpenCV in '..\OpenCV.pas',
  highGui in '..\highGui.pas';

{$R *.res}
const w =  500 ;
var  imgA,imgB: pIplImage;
     storage : pCvMemStorage;
     contours : pCvSeq;
     contour_num : integer;
     i1,i2,i,j : integer;
     point : pInteger;

begin
  imgA := cvLoadImage( 'image_sample12.bmp', -1);
  imgB := cvCreateImage( cvSize_(imgA.width, imgA.Height), IPL_DEPTH_8U, 3);
  //--- Smooth
//  cvSmooth( imgA, imgB, CV_GAUSSIAN, 7, 0, 0);

  //-- Contours
  cvCvtColor( imgA, imgB, CV_GRAY2BGR);
  storage := cvCreateMemStorage( 0);
  contours :=nil;

  contour_num := cvFindContours( imgA, storage, @contours, sizeof(CvContour), CV_RETR_LIST,
				                         CV_CHAIN_APPROX_NONE, cvPoint_(0,0));

  i :=0 ;
  while (i<contour_num) do
  begin
    for j:=0 to contours.total-1 do
    begin
      point := pInteger(cvGetSeqElem( contours, j));
      i1 := point^; inc(point); i2 := point^;
      cvSet2D( imgB,i1,i2, CV_RGB( 255,0,0));
    end;
    inc(i,contours.total);
    contours := contours.h_next;
  end;
  cvDrawContours( imgB, contours, CV_RGB( 255, 0, 0), CV_RGB( 255, 0, 0), 1, 1, 8,cvPoint_(0,0));
  cvNamedWindow( 'image', 1 );
  cvShowImage( 'image', imgB );
  cvWaitKey(0);

end.



⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?