2013-10-06 11:48:40 +02:00
|
|
|
|
// *****************************************************************
|
|
|
|
|
// Delphi-OpenCV Demo
|
|
|
|
|
// Copyright (C) 2013 Project Delphi-OpenCV
|
|
|
|
|
// ****************************************************************
|
|
|
|
|
// Contributor:
|
|
|
|
|
// Laentir Valetov
|
|
|
|
|
// email:laex@bk.ru
|
|
|
|
|
// ****************************************************************
|
|
|
|
|
// You may retrieve the latest version of this file at the GitHub,
|
|
|
|
|
// located at git://github.com/Laex/Delphi-OpenCV.git
|
|
|
|
|
// ****************************************************************
|
|
|
|
|
// The contents of this file are used with permission, subject to
|
|
|
|
|
// the Mozilla Public License Version 1.1 (the "License"); you may
|
|
|
|
|
// not use this file except in compliance with the License. You may
|
|
|
|
|
// obtain a copy of the License at
|
|
|
|
|
// http://www.mozilla.org/MPL/MPL-1_1Final.html
|
|
|
|
|
//
|
|
|
|
|
// Software distributed under the License is distributed on an
|
|
|
|
|
// "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
|
// implied. See the License for the specific language governing
|
|
|
|
|
// rights and limitations under the License.
|
|
|
|
|
// *******************************************************************
|
|
|
|
|
|
2013-06-05 09:03:27 +02:00
|
|
|
|
program cv_GoodFeaturesToTrack;
|
|
|
|
|
|
|
|
|
|
{$APPTYPE CONSOLE}
|
|
|
|
|
{$R *.res}
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
|
System.SysUtils,
|
|
|
|
|
highgui_c,
|
|
|
|
|
core_c,
|
|
|
|
|
Core.types_c,
|
|
|
|
|
imgproc_c,
|
2014-05-19 21:29:48 +02:00
|
|
|
|
imgproc.types_c,
|
|
|
|
|
uResourcePaths;
|
2013-06-05 09:03:27 +02:00
|
|
|
|
|
|
|
|
|
Const
|
2014-05-19 21:29:48 +02:00
|
|
|
|
ImgFilename = cResourceMedia + 'pic5.bmp';
|
2013-06-05 09:03:27 +02:00
|
|
|
|
|
|
|
|
|
type
|
|
|
|
|
TPointsArr = array [0 .. 250] of TCvPoint2D32f;
|
|
|
|
|
PPointsArr = ^TPointsArr;
|
|
|
|
|
|
|
|
|
|
var
|
|
|
|
|
img1, img2, eig, temp: PIplImage;
|
|
|
|
|
|
2014-05-19 21:29:48 +02:00
|
|
|
|
points: array [0 .. 1] of PPointsArr;
|
|
|
|
|
pointsRow1: TPointsArr;
|
2013-06-05 09:03:27 +02:00
|
|
|
|
ipar1, count, j: integer;
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
|
try
|
|
|
|
|
ipar1 := 100;
|
2014-05-19 21:29:48 +02:00
|
|
|
|
img1 := cvLoadImage(ImgFilename, CV_LOAD_IMAGE_UNCHANGED);
|
|
|
|
|
img2 := cvCreateImage(cvGetSize(img1), IPL_DEPTH_8U, 1);
|
|
|
|
|
cvCvtColor(img1, img2, CV_RGB2GRAY);
|
|
|
|
|
eig := cvCreateImage(cvGetSize(img2), 32, 1);
|
|
|
|
|
temp := cvCreateImage(cvGetSize(img2), 32, 1);
|
2013-06-05 09:03:27 +02:00
|
|
|
|
|
|
|
|
|
points[0] := @pointsRow1[0];
|
2014-05-19 21:29:48 +02:00
|
|
|
|
count := 250;
|
|
|
|
|
cvGoodFeaturesToTrack(img2, eig, temp, @points[0][0], @ipar1, 0.05, 10, nil, 5, 0, 0.09);
|
|
|
|
|
cvFindCornerSubPix(img2, @points[0][0], count, cvSize(5, 5), cvSize(-1, -1),
|
2013-06-05 09:03:27 +02:00
|
|
|
|
cvTermCriteria(CV_TERMCRIT_ITER or CV_TERMCRIT_EPS, 20, 0.03));
|
|
|
|
|
for j := 0 to ipar1 - 1 do
|
|
|
|
|
begin
|
2014-05-19 21:29:48 +02:00
|
|
|
|
cvCircle(img1, cvPointFrom32f(points[0][j]), 3, CV_RGB(0, 255, 255), -1, 8, 0);
|
|
|
|
|
cvCircle(img1, cvPointFrom32f(points[0][j]), 8, CV_RGB(255, 0, 0), -1, 8, 0);
|
2013-06-05 09:03:27 +02:00
|
|
|
|
end;
|
2014-05-19 21:29:48 +02:00
|
|
|
|
cvNamedWindow('bb', 1);
|
|
|
|
|
cvShowImage('bb', img1);
|
2013-06-05 09:03:27 +02:00
|
|
|
|
cvWaitKey(0);
|
|
|
|
|
cvReleaseImage(img1);
|
|
|
|
|
cvReleaseImage(img2);
|
|
|
|
|
cvReleaseImage(eig);
|
|
|
|
|
cvReleaseImage(temp);
|
|
|
|
|
cvDestroyAllWindows;
|
|
|
|
|
except
|
|
|
|
|
on E: Exception do
|
2014-05-19 21:29:48 +02:00
|
|
|
|
WriteLn(E.ClassName, ': ', E.Message);
|
2013-06-05 09:03:27 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
end.
|