2015-01-23 23:07:17 +01:00
|
|
|
(*
|
|
|
|
**************************************************************************************************
|
|
|
|
Project Delphi-OpenCV
|
|
|
|
**************************************************************************************************
|
|
|
|
Contributor:
|
|
|
|
Laentir Valetov
|
|
|
|
email:laex@bk.ru
|
|
|
|
Mikhail Grigorev
|
|
|
|
email:sleuthound@gmail.com
|
|
|
|
**************************************************************************************************
|
|
|
|
You may retrieve the latest version of this file at the GitHub,
|
|
|
|
located at git://github.com/Laex/Delphi-OpenCV.git
|
|
|
|
**************************************************************************************************
|
|
|
|
License:
|
|
|
|
The contents of this file are 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/
|
2014-04-04 19:14:06 +02:00
|
|
|
|
2015-01-23 23:07:17 +01:00
|
|
|
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.
|
|
|
|
|
|
|
|
Alternatively, the contents of this file may be used under the terms of the
|
|
|
|
GNU Lesser General Public License (the "LGPL License"), in which case the
|
|
|
|
provisions of the LGPL License are applicable instead of those above.
|
|
|
|
If you wish to allow use of your version of this file only under the terms
|
|
|
|
of the LGPL License and not to allow others to use your version of this file
|
|
|
|
under the MPL, indicate your decision by deleting the provisions above and
|
|
|
|
replace them with the notice and other provisions required by the LGPL
|
|
|
|
License. If you do not delete the provisions above, a recipient may use
|
|
|
|
your version of this file under either the MPL or the LGPL License.
|
|
|
|
|
|
|
|
For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html
|
|
|
|
**************************************************************************************************
|
|
|
|
Warning: Using Delphi XE3 syntax!
|
|
|
|
**************************************************************************************************
|
|
|
|
The Initial Developer of the Original Code:
|
|
|
|
OpenCV: open source computer vision library
|
|
|
|
Homepage: http://ocv.org
|
|
|
|
Online docs: http://docs.ocv.org
|
|
|
|
Q&A forum: http://answers.ocv.org
|
|
|
|
Dev zone: http://code.ocv.org
|
|
|
|
**************************************************************************************************
|
|
|
|
Original file:
|
|
|
|
opencv\modules\highgui\include\opencv2\highgui.hpp
|
|
|
|
*************************************************************************************************
|
|
|
|
*)
|
2013-09-12 12:50:55 +02:00
|
|
|
|
2014-05-22 16:23:41 +02:00
|
|
|
unit ocv.highgui;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
|
|
|
interface
|
|
|
|
|
2014-05-22 08:53:48 +02:00
|
|
|
uses
|
2013-09-12 12:50:55 +02:00
|
|
|
WinApi.Windows,
|
2014-05-22 16:23:41 +02:00
|
|
|
ocv.mat,
|
|
|
|
ocv.core.types_c,
|
|
|
|
ocv.highgui_c;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
2014-05-22 08:53:48 +02:00
|
|
|
type
|
2013-09-12 12:50:55 +02:00
|
|
|
|
|
|
|
// Attention!
|
|
|
|
// The sequence of function declarations interface must match the
|
|
|
|
// sequence of function declarations in the project "opencv_classes" (C++)
|
|
|
|
|
2014-10-04 23:44:14 +02:00
|
|
|
TccvVideoCapture = class
|
2014-04-04 19:14:06 +02:00
|
|
|
function open(device: Integer): bool; overload; virtual; stdcall; abstract;
|
|
|
|
function openfile(filename: pAnsiChar): bool; overload; virtual; stdcall; abstract;
|
|
|
|
function isOpened(): bool; virtual; stdcall; abstract;
|
|
|
|
procedure release(); virtual; stdcall; abstract;
|
|
|
|
function grab(): bool; virtual; stdcall; abstract;
|
2014-10-04 23:44:14 +02:00
|
|
|
function retrieve(Var image: TccvMat; flag: Integer): bool; virtual; stdcall; abstract;
|
|
|
|
function read(Var image: TccvMat): bool; virtual; stdcall; abstract;
|
2014-04-04 19:14:06 +02:00
|
|
|
function setValue(propId: Integer; value: double): bool; virtual; stdcall; abstract;
|
|
|
|
function getValue(propId: Integer): double; virtual; stdcall; abstract;
|
2014-10-04 23:44:14 +02:00
|
|
|
// ---------------------------
|
|
|
|
class function Create: TccvVideoCapture; overload;
|
|
|
|
class function Create(device: Integer): TccvVideoCapture; overload;
|
|
|
|
class function Create(filename: pAnsiChar): TccvVideoCapture; overload;
|
|
|
|
procedure Free; reintroduce;
|
2013-09-12 12:50:55 +02:00
|
|
|
end;
|
|
|
|
|
2014-10-04 23:44:14 +02:00
|
|
|
// Flags for namedWindow
|
2014-05-22 08:53:48 +02:00
|
|
|
const
|
2013-09-12 12:50:55 +02:00
|
|
|
WINDOW_NORMAL = $00000000;
|
|
|
|
// the user can resize the window (no constraint) / also use to switch a fullscreen window to a normal size
|
|
|
|
WINDOW_AUTOSIZE = $00000001; // the user cannot resize the window, the size is constrainted by the image displayed
|
2014-10-04 23:44:14 +02:00
|
|
|
WINDOW_OPENGL = $00001000; // window with opengl support
|
2013-09-12 12:50:55 +02:00
|
|
|
|
2014-04-04 19:14:06 +02:00
|
|
|
WINDOW_FULLSCREEN = 1; // change the window to fullscreen
|
2014-10-04 23:44:14 +02:00
|
|
|
WINDOW_FREERATIO = $00000100; // the image expends as much as it can (no ratio constraint)
|
|
|
|
WINDOW_KEEPRATIO = $00000000; // the ratio of the image is respected
|
2013-09-12 12:50:55 +02:00
|
|
|
|
|
|
|
// CV_EXPORTS_W void namedWindow(const String& winname, int flags = WINDOW_AUTOSIZE);
|
|
|
|
procedure namedWindow(const winname: String; const flags: Integer = WINDOW_AUTOSIZE);
|
|
|
|
// CV_EXPORTS_W void destroyWindow(const String& winname);
|
|
|
|
procedure destroyWindow(const winname: String);
|
|
|
|
// CV_EXPORTS_W void destroyAllWindows();
|
|
|
|
procedure destroyAllWindows();
|
|
|
|
// CV_EXPORTS_W int startWindowThread();
|
|
|
|
function startWindowThread(): Integer;
|
|
|
|
// CV_EXPORTS_W int waitKey(int delay = 0);
|
|
|
|
function waitKey(const delay: Integer = 0): Integer;
|
|
|
|
// CV_EXPORTS_W void imshow(const String& winname, InputArray mat);
|
2014-10-04 23:44:14 +02:00
|
|
|
procedure imshow(const winname: String; const mat: TccvMat);
|
2013-09-12 12:50:55 +02:00
|
|
|
// CV_EXPORTS_W void resizeWindow(const String& winname, int width, int height);
|
|
|
|
procedure resizeWindow(const winname: String; const width, height: Integer);
|
|
|
|
// CV_EXPORTS_W void moveWindow(const String& winname, int x, int y);
|
|
|
|
procedure moveWindow(const winname: String; const x, y: Integer);
|
|
|
|
// CV_EXPORTS_W void setWindowProperty(const String& winname, int prop_id, double prop_value);
|
|
|
|
procedure setWindowProperty(const winname: String; const prop_id: Integer; const prop_value: double);
|
|
|
|
// CV_EXPORTS_W double getWindowProperty(const String& winname, int prop_id);
|
|
|
|
function getWindowProperty(const winname: String; const prop_id: Integer): double;
|
|
|
|
// CV_EXPORTS int createTrackbar(const String& trackbarname, const String& winname,
|
|
|
|
// int* value, int count,
|
|
|
|
// TrackbarCallback onChange = 0,
|
|
|
|
// void* userdata = 0);
|
2014-10-04 23:44:14 +02:00
|
|
|
function createTrackbar(const trackbarname: String; const winname: String; value: PInteger; count: Integer;
|
|
|
|
onChange: CvTrackbarCallback2 = nil; userdata: Pointer = nil): Integer;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
|
|
|
// CV_EXPORTS_W Mat imread( const string& filename, int flags=1 );
|
2014-10-04 23:44:14 +02:00
|
|
|
function imread(const filename: string; flag: Integer = 1): TccvMat;
|
2013-09-12 12:50:55 +02:00
|
|
|
// CV_EXPORTS_W bool imwrite( const string& filename, InputArray img, const vector<int>& params=vector<int>());
|
2015-01-23 13:50:01 +01:00
|
|
|
//function imwrite(const filename: String; const img: TccvMat): bool;
|
2014-04-04 19:14:06 +02:00
|
|
|
|
2014-05-22 08:53:48 +02:00
|
|
|
type
|
2014-04-04 19:14:06 +02:00
|
|
|
TIplImageRecordHelper = record helper for TIplImage
|
2014-10-04 23:44:14 +02:00
|
|
|
function InitFromMat(const mat: TccvMat): TIplImage;
|
2014-04-04 19:14:06 +02:00
|
|
|
end;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
|
|
|
implementation
|
|
|
|
|
2014-05-22 08:53:48 +02:00
|
|
|
uses
|
2014-05-22 16:23:41 +02:00
|
|
|
ocv.lib,
|
|
|
|
ocv.cvutils,
|
|
|
|
ocv.core_c;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
2014-10-04 23:44:14 +02:00
|
|
|
function CreateVideoCapture: TccvVideoCapture; stdcall; external opencv_classes_lib name 'CreateVideoCapture'; overload;
|
2014-10-18 01:12:32 +02:00
|
|
|
function CreateVideoCapture(device: Integer): TccvVideoCapture; stdcall;
|
|
|
|
external opencv_classes_lib name 'CreateVideoCaptureDevice'; overload;
|
|
|
|
function CreateVideoCapture(filename: pAnsiChar): TccvVideoCapture; stdcall;
|
|
|
|
external opencv_classes_lib name 'CreateVideoCaptureFileName'; overload;
|
2014-10-04 23:44:14 +02:00
|
|
|
procedure ReleaseVideoCapture(ex: TccvVideoCapture); stdcall; external opencv_classes_lib;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
2015-01-23 13:50:01 +01:00
|
|
|
// function _imread(const filename: pCvChar; flag: Integer): TccvMat; external opencv_classes_lib name '_imread';
|
|
|
|
// function _imwrite(const filename: pCvChar; const img: TccvMat): bool; external opencv_classes_lib name '_imwrite';
|
2014-04-04 19:14:06 +02:00
|
|
|
|
2014-10-04 23:44:14 +02:00
|
|
|
function imread(const filename: string; flag: Integer): TccvMat;
|
2013-09-12 12:50:55 +02:00
|
|
|
begin
|
2015-01-23 13:50:01 +01:00
|
|
|
// Result := _imread(c_str(filename), flag);
|
|
|
|
Result := TccvMat.Create(cvLoadImage(pAnsiChar(AnsiString(filename)), flag));
|
2013-09-12 12:50:55 +02:00
|
|
|
end;
|
|
|
|
|
2015-01-23 13:50:01 +01:00
|
|
|
// function imwrite(const filename: String; const img: TccvMat): bool;
|
|
|
|
// begin
|
|
|
|
// Result := _imwrite(c_str(filename), img);
|
|
|
|
// end;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
|
|
|
procedure namedWindow(const winname: String; const flags: Integer = WINDOW_AUTOSIZE);
|
|
|
|
begin
|
2014-04-04 19:14:06 +02:00
|
|
|
cvNamedWindow(c_str(winname), flags);
|
2013-09-12 12:50:55 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure destroyWindow(const winname: String);
|
|
|
|
begin
|
|
|
|
cvDestroyWindow(c_str(winname));
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure destroyAllWindows();
|
|
|
|
begin
|
|
|
|
cvDestroyAllWindows();
|
|
|
|
end;
|
|
|
|
|
|
|
|
function startWindowThread(): Integer;
|
|
|
|
begin
|
|
|
|
Result := cvStartWindowThread();
|
|
|
|
end;
|
|
|
|
|
|
|
|
function waitKey(const delay: Integer = 0): Integer;
|
|
|
|
begin
|
|
|
|
Result := cvWaitKey(delay);
|
|
|
|
end;
|
|
|
|
|
2014-10-04 23:44:14 +02:00
|
|
|
procedure imshow(const winname: String; const mat: TccvMat);
|
2013-09-12 12:50:55 +02:00
|
|
|
Var
|
|
|
|
IplImage: TIplImage;
|
|
|
|
begin
|
2014-04-04 19:14:06 +02:00
|
|
|
IplImage.InitFromMat(mat);
|
|
|
|
cvShowImage(c_str(winname), @IplImage);
|
2013-09-12 12:50:55 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure resizeWindow(const winname: String; const width, height: Integer);
|
|
|
|
begin
|
2014-04-04 19:14:06 +02:00
|
|
|
cvResizeWindow(c_str(winname), width, height);
|
2013-09-12 12:50:55 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure moveWindow(const winname: String; const x, y: Integer);
|
|
|
|
begin
|
2014-04-04 19:14:06 +02:00
|
|
|
cvMoveWindow(c_str(winname), x, y);
|
2013-09-12 12:50:55 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure setWindowProperty(const winname: String; const prop_id: Integer; const prop_value: double);
|
|
|
|
begin
|
2014-04-04 19:14:06 +02:00
|
|
|
cvSetWindowProperty(c_str(winname), prop_id, prop_value);
|
2013-09-12 12:50:55 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function getWindowProperty(const winname: String; const prop_id: Integer): double;
|
|
|
|
begin
|
2014-04-04 19:14:06 +02:00
|
|
|
Result := cvGetWindowProperty(c_str(winname), prop_id);
|
2013-09-12 12:50:55 +02:00
|
|
|
end;
|
|
|
|
|
2014-10-04 23:44:14 +02:00
|
|
|
function createTrackbar(const trackbarname: String; const winname: String; value: PInteger; count: Integer;
|
|
|
|
onChange: CvTrackbarCallback2 = nil; userdata: Pointer = nil): Integer;
|
2014-04-04 19:14:06 +02:00
|
|
|
begin
|
|
|
|
Result := cvCreateTrackbar2(c_str(trackbarname), c_str(winname), value, count, onChange, userdata);
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ TIplImageRecordHelper }
|
|
|
|
|
2014-10-04 23:44:14 +02:00
|
|
|
function TIplImageRecordHelper.InitFromMat(const mat: TccvMat): TIplImage;
|
2013-09-12 12:50:55 +02:00
|
|
|
begin
|
2014-04-04 19:14:06 +02:00
|
|
|
Assert(mat.dims <= 2);
|
|
|
|
cvInitImageHeader(@Self, CvSize(mat.cols, mat.rows), cvIplDepth(mat.flags), mat.channels);
|
|
|
|
cvSetData(@Self, mat.data, mat.step1);
|
2013-09-12 12:50:55 +02:00
|
|
|
end;
|
|
|
|
|
2014-10-04 23:44:14 +02:00
|
|
|
{ TocvVideoCapture }
|
|
|
|
|
|
|
|
class function TccvVideoCapture.Create: TccvVideoCapture;
|
|
|
|
begin
|
|
|
|
Result := CreateVideoCapture;
|
|
|
|
end;
|
|
|
|
|
|
|
|
class function TccvVideoCapture.Create(device: Integer): TccvVideoCapture;
|
|
|
|
begin
|
|
|
|
Result := CreateVideoCapture(device);
|
|
|
|
end;
|
|
|
|
|
|
|
|
class function TccvVideoCapture.Create(filename: pAnsiChar): TccvVideoCapture;
|
|
|
|
begin
|
|
|
|
Result := CreateVideoCapture(filename);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TccvVideoCapture.Free;
|
|
|
|
begin
|
|
|
|
ReleaseVideoCapture(Self);
|
|
|
|
end;
|
|
|
|
|
2013-09-12 12:50:55 +02:00
|
|
|
end.
|