From eecb9bdafbef6314ede54f82d595c8a2c6dde262 Mon Sep 17 00:00:00 2001 From: Michael Grigorev Date: Tue, 23 Apr 2013 12:15:31 +0600 Subject: [PATCH] Add samples [+] MotionDetect --- .../MultiDemo/MotionDetect/MotionDetect.dpr | 95 ++++++++++ .../MultiDemo/MotionDetect/MotionDetect.dproj | 164 ++++++++++++++++++ .../MultiDemo/MotionDetect/MotionDetect.res | Bin 0 -> 96 bytes samples/Samples.groupproj | 18 +- 4 files changed, 274 insertions(+), 3 deletions(-) create mode 100644 samples/MultiDemo/MotionDetect/MotionDetect.dpr create mode 100644 samples/MultiDemo/MotionDetect/MotionDetect.dproj create mode 100644 samples/MultiDemo/MotionDetect/MotionDetect.res diff --git a/samples/MultiDemo/MotionDetect/MotionDetect.dpr b/samples/MultiDemo/MotionDetect/MotionDetect.dpr new file mode 100644 index 0000000..12fd5b8 --- /dev/null +++ b/samples/MultiDemo/MotionDetect/MotionDetect.dpr @@ -0,0 +1,95 @@ +program MotionDetect; + +{$APPTYPE CONSOLE} +{$POINTERMATH ON} +{$R *.res} + +uses + System.SysUtils, + uLibName in '..\..\..\include\uLibName.pas', + highgui_c in '..\..\..\include\highgui\highgui_c.pas', + imgproc.types_c in '..\..\..\include\imgproc\imgproc.types_c.pas', + imgproc_c in '..\..\..\include\imgproc\imgproc_c.pas', + imgproc in '..\..\..\include\imgproc\imgproc.pas', + core in '..\..\..\include\core\core.pas', + Core.types_c in '..\..\..\include\core\Core.types_c.pas', + core_c in '..\..\..\include\core\core_c.pas', + Math; + + +var + storage: pCvMemStorage = nil; + capture: pCvCapture = nil; + frame: pIplImage = nil; + frame_grey: pIplImage = nil; + difference_img: pIplImage = nil; + oldframe_grey: pIplImage = nil; + contours: pCvSeq = nil; + c: pCvSeq = nil; + //rect: TCvRect; + rect2d: TCvBox2D; + key: integer; + first: boolean = true; +begin + try + capture := cvCreateCameraCapture(0); + storage := cvCreateMemStorage(0); + frame := cvQueryFrame(capture); + frame_grey := cvCreateImage(cvSize(frame^.width, frame^.height), IPL_DEPTH_8U, 1); + + while true do + begin + frame := cvQueryFrame(capture); + if frame = nil then + break; + cvCvtColor(frame, frame_grey, CV_RGB2GRAY); + if first then + begin + difference_img := cvCloneImage(frame_grey); + oldframe_grey := cvCloneImage(frame_grey); + cvConvertScale(frame_grey, oldFrame_grey, 1.0, 0.0); + first := false; + end; + cvAbsDiff(oldframe_grey, frame_grey, difference_img); + cvSmooth(difference_img, difference_img, CV_BLUR); + cvThreshold(difference_img, difference_img, 25, 255, CV_THRESH_BINARY); + cvFindContours(difference_img, storage, @contours, SizeOf(TCvContour), CV_RETR_LIST, CV_CHAIN_APPROX_NONE, cvPoint(0,0)); + c := contours; + while (c <> nil) do + begin + //rect := cvBoundingRect(c, 0); + rect2d := cvMinAreaRect2(c); + {cvRectangle(frame, cvPoint(rect.x, rect.y), + cvPoint(rect.x+rect.width, rect.y+rect.height), + cvScalar(0, 0, 255, 0), 2, 8, 0);} + cvRectangle(frame, cvPoint(Round(rect2d.center.x-rect2d.size.width/2), + Round(rect2d.center.y-rect2d.size.height/2)), + cvPoint(Round(rect2d.center.x+rect2d.size.width/2), + Round(rect2d.center.y+rect2d.size.height/2)), + cvScalar(0, 0, 255, 0), 2, 8, 0); + c:= c.h_next; + end; + cvShowImage('Output Image', frame); + cvShowImage('Difference Image', difference_img); + cvConvertScale(frame_grey, oldframe_grey, 1.0, 0.0); + cvClearMemStorage(storage); + contours := nil; + c := nil; + key := cvWaitKey(33); + if (key = 27) then + Break; + end; + // Îcâîáîæäàåì ðåcóðcû + cvReleaseMemStorage(storage); + cvReleaseCapture(capture); + cvReleaseImage(oldframe_grey); + cvReleaseImage(difference_img); + cvReleaseImage(frame); + cvReleaseImage(frame_grey); + cvDestroyAllWindows(); + except + on E: Exception do + WriteLn(E.ClassName, ': ', E.Message); + end; + +end. diff --git a/samples/MultiDemo/MotionDetect/MotionDetect.dproj b/samples/MultiDemo/MotionDetect/MotionDetect.dproj new file mode 100644 index 0000000..7f9a760 --- /dev/null +++ b/samples/MultiDemo/MotionDetect/MotionDetect.dproj @@ -0,0 +1,164 @@ + + + {724F6D9A-7787-4B1B-A8B5-A940BFF50F2A} + MotionDetect.dpr + True + Release + 1 + Console + None + 14.4 + Win32 + + + true + + + true + Base + true + + + true + Base + true + + + true + Cfg_1 + true + true + + + true + Base + true + + + true + Cfg_2 + true + true + + + 1049 + false + false + false + 00400000 + CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=;CFBundleName=;CFBundleDisplayName=;CFBundleIdentifier=;CFBundleVersion=;CFBundlePackageType=;CFBundleSignature=;CFBundleAllowMixedLocalizations=;CFBundleExecutable= + false + System;Xml;Data;Datasnap;Web;Soap;Winapi;$(DCC_Namespace) + false + + + 1033 + Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) + CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments= + + + false + RELEASE;$(DCC_Define) + false + 0 + + + None + 1033 + .\..\..\..\bin + CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments= + + + DEBUG;$(DCC_Define) + true + false + + + None + 1033 + .\..\..\..\bin + CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments= + + + + MainSource + + + + + + + + + + + Cfg_2 + Base + + + Base + + + Cfg_1 + Base + + + + Delphi.Personality.12 + + + + + MotionDetect.dpr + + + False + False + 1 + 0 + 0 + 0 + False + False + False + False + False + 1049 + 1251 + + + + + 1.0.0.0 + + + + + + 1.0.0.0 + + + + + + + + + + + + Microsoft Office 2000 Sample Automation Server Wrapper Components + Microsoft Office XP Sample Automation Server Wrapper Components + + + + False + True + False + + + 12 + + + + diff --git a/samples/MultiDemo/MotionDetect/MotionDetect.res b/samples/MultiDemo/MotionDetect/MotionDetect.res new file mode 100644 index 0000000000000000000000000000000000000000..743599575b02e97248bade49ed2e3eabafe25a0a GIT binary patch literal 96 zcmZQzU|>)H;{X347|28cOhBFu5dZ(r#Sp;Y!{Epe!r;c>&k)4m3uHM0X?F%!AS)QE O%YcEC1!e#vkO2UW7YiT& literal 0 HcmV?d00001 diff --git a/samples/Samples.groupproj b/samples/Samples.groupproj index eed7a98..3d3546d 100644 --- a/samples/Samples.groupproj +++ b/samples/Samples.groupproj @@ -204,6 +204,9 @@ + + + Default.Personality.12 @@ -815,14 +818,23 @@ + + + + + + + + + - + - + - +