unit MainForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OpenCV, IPL;
type
TFrmMain = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FrmMain: TFrmMain;
box: CVRect;
implementation
{$R *.dfm}
procedure MouseCallback(event, x, y, flags: Integer; param: Pointer); cdecl;
var
image: PIplImage;
begin
image := PIplImage(param);
case event of
CV_EVENT_MOUSEMOVE:
ShowMessage('d');
end;
end;
procedure SwitchCallback(pos: Integer);
begin
pos := cvGetTrackbarPos('Switch', 'Example1');
ShowMessage(IntToStr(pos));
end;
procedure TFrmMain.Button1Click(Sender: TObject);
var
img: PIplImage;
smt: PIplImage;
iot: PIplImage;
i: Integer;
threshold_type: Integer;
adaptive_method: Integer;
block_size: Integer;
offset: Double;
value: PInteger;
sz: TSize;
pnt: CvPoint;
vl: CvScalar;
storage: PCvMemStorage;
res: PCvSeq;
//锐化
knl: PCvMat;
pdata: array[0..9] of float;
p: PFloat;
//adaptThresh 15 1 1 71 15 ../Data/cal3-L.bmp
begin
threshold_type := CV_THRESH_BINARY;
adaptive_method := CV_ADAPTIVE_THRESH_MEAN_C;
block_size := 71;
offset := 30;
img := cvLoadImage(PChar(ExtractFilePath(ParamStr(0)) + '2.jpg'), CV_LOAD_IMAGE_GRAYSCALE);
smt := cvCloneImage(img);
iot := cvCloneImage(smt);
//cvSmooth(img, smt, CV_GAUSSIAN, 5, 5);
cvCanny(img, smt, 30, 60);
// storage := cvCreateMemStorage(0);
// res := cvHoughCircles(smt, storage, CV_HOUGH_GRADIENT, 1, 100, 150, 55, 0, 0);
// for i := 0 to res^.total - 1 do
// begin
// p := PFloat(cvGetSeqElem(res, i));
// pnt := cvPoint_(cvRound(p^), cvRound(p^));
// Inc(p);
// pnt.y := cvRound(p^);
// Inc(p);
// cvCircle(smt, pnt, cvRound(p^), CV_RGB($33, $55, $77));
// end;
cvNamedWindow('Example1', CV_WINDOW_AUTOSIZE);
cvNamedWindow('Example2', CV_WINDOW_AUTOSIZE);
//cvSetMouseCallback('Example1', MouseCallback, smt);
//cvCreateTrackbar('Switch', 'Example1', value, 1, SwitchCallback);
cvShowImage('Example1', img);
cvShowImage('Example2', smt);
cvWaitKey(0);
cvReleaseImage(img);
cvReleaseImage(smt);
cvDestroyWindow('Example1');
cvDestroyWindow('Example2');
end;
procedure TFrmMain.Button2Click(Sender: TObject);
var
Igray, It, Iat: PIplImage;
threshold: Double;
threshold_type: Integer;
adaptive_method: Integer;
block_size: Integer;
offset: Double;
sz: TSize;
//adaptThresh 15 1 1 71 15 ../Data/cal3-L.bmp
begin
threshold := 82;
threshold_type := CV_THRESH_BINARY;
adaptive_method := CV_ADAPTIVE_THRESH_MEAN_C;
block_size := 71;
offset := 25;
Igray := cvLoadImage(PChar(ExtractFilePath(ParamStr(0)) + '01.jpg'), CV_LOAD_IMAGE_GRAYSCALE);
if not Assigned(Igray) then
Exit;
It := cvCreateImage(cvSize_(Igray.Width, Igray.Height), IPL_DEPTH_8U, 1);
Iat := cvCreateImage(cvSize_(Igray.Width, Igray.Height), IPL_DEPTH_8U, 1);
//Threshold
cvThreshold(Igray, It, threshold, 255, threshold_type);
cvAdaptiveThreshold(Igray, Iat, 255, adaptive_method, threshold_type, block_size, offset);
cvSaveImage('c:\1.bmp', Iat);
cvNamedWindow('Raw', 1);
cvNamedWindow('Threshold', 1);
cvNamedWindow('Adaptive Threshold', 1);
cvShowImage('Raw', Igray);
cvShowImage('Threshold', It);
cvShowImage('Adaptive Threshold', Iat);
cvWaitKey(0);
cvReleaseImage(Igray);
cvReleaseImage(It);
cvReleaseImage(Iat);
cvDestroyWindow('Raw');
cvDestroyWindow('Threshhold');
cvDestroyWindow('Adaptive Threshold');
end;
end.