2015-07-03 22:00:09 +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
|
2014-05-22 16:23:41 +02:00
|
|
|
|
|
2015-07-03 22:00:09 +02: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.
|
|
|
|
|
*******************************************************************
|
|
|
|
|
*)
|
2013-03-27 23:20:08 +01:00
|
|
|
|
program cv_LoadVideo;
|
2013-01-01 13:29:34 +01:00
|
|
|
|
|
|
|
|
|
uses
|
2013-04-05 13:36:47 +02:00
|
|
|
|
System.SysUtils,
|
2014-05-22 16:23:41 +02:00
|
|
|
|
ocv.highgui_c,
|
|
|
|
|
ocv.core_c,
|
|
|
|
|
ocv.core.types_c,
|
|
|
|
|
ocv.imgproc_c,
|
|
|
|
|
ocv.imgproc.types_c,
|
2014-05-20 07:10:43 +02:00
|
|
|
|
uResourcePaths;
|
2013-01-01 13:29:34 +01:00
|
|
|
|
|
|
|
|
|
const
|
|
|
|
|
// declare video filename
|
2014-05-20 07:10:43 +02:00
|
|
|
|
VIDEO_FILE_NAME = cResourceMedia + '768x576.avi';
|
2013-01-01 13:29:34 +01:00
|
|
|
|
// declare escape char
|
|
|
|
|
ESCAPE_CHAR = 27;
|
|
|
|
|
|
|
|
|
|
var
|
|
|
|
|
// declate an opencv video file capture object, users can use this object to
|
|
|
|
|
// interact with the video file, get/set properties and also grab video frames
|
|
|
|
|
capture: pCVCapture;
|
|
|
|
|
// declare an opencv image pointer variable
|
|
|
|
|
frame: pIplImage;
|
|
|
|
|
// declate a key variable to get user key pressed
|
|
|
|
|
key: integer;
|
2013-04-05 13:36:47 +02:00
|
|
|
|
|
2013-01-01 13:29:34 +01:00
|
|
|
|
begin
|
2013-04-05 13:36:47 +02:00
|
|
|
|
try
|
|
|
|
|
// create capture object for specific video filename
|
|
|
|
|
capture := cvCreateFileCapture(VIDEO_FILE_NAME);
|
|
|
|
|
// check if capture assigned, if not then it means that opencv can not open
|
|
|
|
|
// the requested file, opencv uses VFW to open the files so some file formats
|
|
|
|
|
// are not fully supported (can be enhence with FFMPEG support but this is
|
|
|
|
|
// beyond our scope right now
|
|
|
|
|
if Assigned(capture) then
|
2013-01-01 13:29:34 +01:00
|
|
|
|
begin
|
2013-04-05 13:36:47 +02:00
|
|
|
|
// create display window
|
|
|
|
|
cvNamedWindow('video');
|
|
|
|
|
// reset user key pressed
|
|
|
|
|
key := 0;
|
|
|
|
|
// loop while user didn't press ESCAPE
|
|
|
|
|
while key <> ESCAPE_CHAR do
|
|
|
|
|
begin
|
|
|
|
|
// start grabbing frames, single frame at a time, this method is a
|
|
|
|
|
// combination of two methods one grab frame and the other advances to the
|
|
|
|
|
// next frame
|
|
|
|
|
//
|
|
|
|
|
// REMARK: do not (!!!) release "frame" object since it is used internally
|
|
|
|
|
// by the capture object is its memory is release when the "capture" object
|
|
|
|
|
// is being destroyed
|
|
|
|
|
frame := cvQueryFrame(capture);
|
|
|
|
|
// check if frame is valid, when you reach end-of-file "frame" object
|
|
|
|
|
// starts to be NIL (since the method advances to the next frame each time
|
|
|
|
|
// is is called...)
|
|
|
|
|
if Assigned(frame) then
|
|
|
|
|
// show frame in window
|
|
|
|
|
cvShowImage('video', frame);
|
|
|
|
|
// wait for user key, delay is in msec so 1000msec = 1sec wait period
|
2015-07-03 22:00:09 +02:00
|
|
|
|
key := cvWaitKey(100);
|
2013-04-05 13:36:47 +02:00
|
|
|
|
end;
|
|
|
|
|
// destroy display windows
|
|
|
|
|
cvDestroyAllWindows;
|
|
|
|
|
// release "capture" object and its related memory
|
|
|
|
|
cvReleaseCapture(capture);
|
2013-01-01 13:29:34 +01:00
|
|
|
|
end;
|
2013-04-05 13:36:47 +02:00
|
|
|
|
except
|
|
|
|
|
on E: Exception do
|
|
|
|
|
Writeln(E.ClassName, ': ', E.Message);
|
2013-01-01 13:29:34 +01:00
|
|
|
|
end;
|
2013-04-05 13:36:47 +02:00
|
|
|
|
|
2013-01-01 13:29:34 +01:00
|
|
|
|
end.
|