OpenCV2.3翻译为Delphi--测试

 

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.

由于文件大小超过csdn限制的70M. Delphi-OpenCV OpenCV version - 2.4.13 Development environment - Delphi 2010-10.1 Contributors: Laentir Valetov (email: laex@bk.ru) Mikhail Grigorev (email: sleuthhound@gmail.com) Requirements: Visual C++ redistributable for Visual Studio 2013 Files: msvcp120.dll, msvcr120.dll, msvcp120d.dll, msvcr120d.dll (1) 32-bit in the "Delphi-OpenCV\redist\VC2013x86\" (2) 64-bit in the "Delphi-OpenCV\redist\VC2013x64\" Shared library FFMPEG 3.2 for Windows can be downloaded from here (3) FFmpeg 32-bit Shared (4) FFmpeg 64-bit Shared Dynamic library OpenCV need to download here Files: _2413.dll and _2413d.dll After installing OpenCV: (5) 32-bit in the C:\OpenCV\build\x86\vc12\bin\ (6) 64-bit in the C:\OpenCV\build\x64\vc12\bin\ Some examples (FFMPEG) required SDL 2.0 and SDL 1.2 (7) SDL.dll and SDL2.dll Copy files OS Windows 64-bit Target platform 64-bit: (2),(4),(6) -> "C:\Windows\System32\" Target platform 32-bit: (1),(3),(5),(7) -> "C:\Windows\SysWOW64\" OS Windows 32-bit Target platform 32-bit: (1),(3),(5),(7) -> "C:\Windows\System32\" How to install: Download the archive. Unzip it to a convenient directory, thus get the following directory structure <PROJECT_ROOT> - Directory, for example, "C:\Delphi\OpenCV\" <bin> <redist> <resource> <samples> <source> Add the search path for the modules of the project in Delphi IDE (Tools-Options-Delphi Options-Library-Library path) <PROJECT_ROOT>\source <PROJECT_ROOT>\source\utils <PROJECT_ROOT>\source\component <PROJECT_ROOT>\source\sdl <PROJECT_ROOT>\source\opengl <PROJECT_ROOT>\source\ffmpeg <PROJECT_ROOT>\resource\facedetectxml where <PROJECT_ROOT> directory, which was unzipped project. To install the components, open and install <PROJECT_ROOT>\source\component\DelphiXX\OpenCVXXX.dpk <PROJECT_ROOT>\source\component\DelphiXX\dclCommonOpenCVXXX.dpk <PROJECT_ROOT>\source\component\DelphiXX\dclVCLOpenCVXXX.dpk <PROJECT_ROOT>\source\component\DelphiXX\dclFMXOpenCVXXX.dpk Open in Delphi IDE and compile: Examples of the use of certain functions and procedures <PROJECT_ROOT>\samples\LibDemo\LibDemo.groupproj Examples of the use of video processing algorithms <PROJECT_ROOT>\samples\MultiDemo\MultiDemo.groupproj Examples of the use of video processing algorithms using VCL.Forms <PROJECT_ROOT>\samples\VCLDemo\VCLDemo.groupproj Examples of using FFMPEG library header files are in the <PROJECT_ROOT>\samples\FFMpeg\FFMPEG.groupproj Examples of use of components <PROJECT_ROOT>\samples\Components\ComponentsDemo.groupproj Donate (PayPal USD) Donate (PayPal EUR) Donate (PayPal RUB) Yandex Money: 410012802258318
由于文件大小超过csdn限制的60M,所以分割成2个文件了,请注意下载。 Delphi-OpenCV (master) OpenCV version - 2.4.8 Development environment - Delphi XE2-XE5 Contributors: Laentir Valetov email: laex@bk.ru Mikhail Grigorev email: sleuthhound@gmail.com How to install: 1.Download the archive Delphi-OpenCV-master.zip 2.Unzip it to a convenient directory, thus get the following directory structure <Directory, such as 'C:\OpenCV\' - <PROJECT_ROOT>> <bin> <component> <include> <opencv_classes> <samples> 3.Add the search path for the modules of the project in Delphi IDE (Tools-Options-Delphi Options-Library-Library path) <PROJECT_ROOT>\Include <PROJECT_ROOT>\Include\core <PROJECT_ROOT>\Include\highgui <PROJECT_ROOT>\Include\imgproc <PROJECT_ROOT>\Include\legacy <PROJECT_ROOT>\Include\nonfree <PROJECT_ROOT>\Include\objdetect <PROJECT_ROOT>\Include\calib3d <PROJECT_ROOT>\Include\contrib <PROJECT_ROOT>\Include\video <PROJECT_ROOT>\Include\ml <PROJECT_ROOT>\Include\stitching <PROJECT_ROOT>\component where <PROJECT_ROOT> directory, which was unzipped project. Additionally, you can specify the path to the library header files FFMPEG <PROJECT_ROOT>\Include\ffmpeg <PROJECT_ROOT>\Include\ffmpeg\ctypes <PROJECT_ROOT>\Include\ffmpeg\libavcodec <PROJECT_ROOT>\Include\ffmpeg\libavfilter <PROJECT_ROOT>\Include\ffmpeg\libavformat <PROJECT_ROOT>\Include\ffmpeg\libavutil <PROJECT_ROOT>\Include\ffmpeg\libswscale Examples of using FFMPEG library header files are in the <PROJECT_ROOT>\Delphi-OpenCV-master\Include\ffmpeg\examples 4.Open in Delphi IDE and compile: Examples of the use of certain functions and procedures <PROJECT_ROOT>\samples\LibDemo.groupproj Examples of the use of video processing algorithms <PROJECT_ROOT>\samples\MultiDemo.groupproj Examples of the use of video processing algorithms using VCL.Forms <PROJECT_ROOT>\samples\VCLDemo.groupproj Examples of use of components. To install the components, open and install <PROJECT_ROOT>\Include\component\OpenCV.dpk <PROJECT_ROOT>\samples\ComponentDemo.groupproj
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值