You are on page 1of 5

27/10/2014 Seguimiento de personas, animales y objetos con OpenCV en Delphi | Delphi Magic

http://delphimagic.blogspot.com/2013/04/seguimiento-de-personas-animales-y.html 1/5
29th April 2013
[http://2.bp.blogspot.com/-uvISlP8tEh0/UX6naYaygrI/AAAAAAAAAnU/Uc_dQ-
v9Tjs/s1600/i1.JPG]
OpenCV para los que no la conozcan, es una biblioteca libre enfocada
hacia la visin artificial, inicialmente desarrollada por Intel bajo licencia
BSD lo que permite que sea usada libremente para un propsito comercial
o de investigacin.
OpenCV es multiplataforma con versiones para Windows, Linux y Mac y
contiene funciones que tratan los temas de proceso de visin,
reconocimiento facial, calibrado de cmaras o robtica.
Esta biblioteca es la base de la herramienta Swistrack
[http://swistrack.sourceforge.net/] que sirve para hacer un seguimiento de
personas, animales y objetos.
El siguiente cdigo se puede ejecutar en Delphi XE2 o superior y lo que
hace es, como veis en la imagen, un seguimiento de las personas que
circulan por la calle rodendolas con un rectngulo de color rojo a medida
que se van desplazando.
Seguimiento de personas,
animales y objetos con OpenCV
en Delphi
1
2
3
4
5
6
7
8
9
10
11
(* /*****************************************************************
// Delphi-OpenCV Demo
// Copyright (C) 2013 Project Delphi-OpenCV
// ****************************************************************
// Contributor:
// Mikhail Grigorev
// email: sleuthhound@gmail.com
// ****************************************************************
// You may retrieve the latest version of this file at the GitHub,
// located at git://github.com/Laex/Delphi-OpenCV.git
// ****************************************************************
?
[#
]
27/10/2014 Seguimiento de personas, animales y objetos con OpenCV en Delphi | Delphi Magic
http://delphimagic.blogspot.com/2013/04/seguimiento-de-personas-animales-y.html 2/5
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// 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 [http://www.mozilla.org/MPL/MPL-1_1Final.html]
//
// 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.
******************************************************************* *)

// JCL_DEBUG_EXPERT_GENERATEJDBG OFF
// JCL_DEBUG_EXPERT_INSERTJDBG OFF
// JCL_DEBUG_EXPERT_DELETEMAPFILE OFF
program MotionDetect;

{$APPTYPE CONSOLE}
{$POINTERMATH ON}
{$R *.res}

uses
System.SysUtils,
Math,
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';

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,

while true do
begin
frame := cvQueryFrame(capture);
if frame = nil then
break;
cvCvtColor(frame, frame_grey, CV_RGB2GRAY);
if first then
27/10/2014 Seguimiento de personas, animales y objetos con OpenCV en Delphi | Delphi Magic
http://delphimagic.blogspot.com/2013/04/seguimiento-de-personas-animales-y.html 3/5
Enlace | Biblioteca Delphi OpenCV [https://github.com/Laex/Delphi-
OpenCV]
Relacionado:
Reconocimiento facial con Delphi
[http://delphimagic.blogspot.com.es/2011/08/reconocimiento-de-caras-con-
delphi.html]
OCR con Tesseract [http://delphimagic.blogspot.com.es/2012/12/ocr-con-
delphi.html]
OCR simplificado [http://delphimagic.blogspot.com.es/2011/08/ocr-simple-con-
delphi.html]
OCR con Delphi [http://delphimagic.blogspot.com.es/2009/04/ocr-con-
delphi.html]
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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
contours := AllocMem(SizeOf(TCvSeq));
cvFindContours(difference_img, storage, @contours, SizeOf(TCvContour), CV_RETR_LIST, CV_CHAIN_APPROX_NONE,
cvPoint(0, 0));
c := contours;
while (c <> nil) do
begin
rect2d := cvMinAreaRect2(c);
cvRectangle(frame, cvPoint(Round(rect2d.center.x - rect2d
Round(rect2d.center.y - rect2d.size.height / 2)), cvPoint(Round(rect2d
Round(rect2d.center.y + rect2d.size.height / 2)), cvScalar(
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);
c := nil;
FreeMem(contours, SizeOf(TCvSeq));
key := cvWaitKey(33);
if (key = 27) then
break;
end;
cvReleaseMemStorage(storage);
cvReleaseCapture(capture);
cvReleaseImage(oldframe_grey);
cvReleaseImage(difference_img);
cvReleaseImage(frame_grey);
cvDestroyAllWindows();
except
on E: Exception do
WriteLn(E.ClassName, ': ', E.Message);
end;

end.
27/10/2014 Seguimiento de personas, animales y objetos con OpenCV en Delphi | Delphi Magic
http://delphimagic.blogspot.com/2013/04/seguimiento-de-personas-animales-y.html 4/5
Chipmunk 2D Physics engine
[http://delphimagic.blogspot.com.es/2013/03/chipmunk-2d-motor-de-fisica.html]
Relacionados sobre imgenes:
Componente para generar efectos graficos
[http://delphimagic.blogspot.com.es/2011/05/programa-para-generar-efectos-
graficos.html]
Librera Exif [http://delphimagic.blogspot.com.es/2012/07/libreria-exif.html]
Componente para manipulacion de imagenes
[http://delphimagic.blogspot.com.es/2009/02/componente-para-manipulacion-
de.html]
Morphing con delphi [http://delphimagic.blogspot.com.es/2012/10/morphing-
con-delphi.html]
Si te ha gustado este artculo, puedes compartirlo haciendo click en los
botones de abajo
Publicado 29th April 2013 por Javier Par
Etiquetas: Graficos, Images, OpenCV, Redes neuronales, Simulacin,
Sistema, Windows

Respuestas
3
Ver comentarios
Salvador 16 de mayo de 2013, 14:50
Hola Javier:
Deseaba contactar contigo e informarte acerca del proyecto
Delphispano
http://www.delphispano.com
No se si lo conoces.
Te dejo mi correo al final del mensaje.
Un saludo,
Salvador Jover
http://www.delphibasico.com/delphi
salvador@delphibasico.com
Responder
Anonymous 19 de mayo de 2013, 19:56
Hola Salvador,
27/10/2014 Seguimiento de personas, animales y objetos con OpenCV en Delphi | Delphi Magic
http://delphimagic.blogspot.com/2013/04/seguimiento-de-personas-animales-y.html 5/5
Responder
Introduce tu comentario...
Comentar como:
Cuenta de Google
Publicar

Vista previa
Te he respondido al email.
Un saludo
Javier
Anonymous 14 de mayo de 2014, 0:49
dcc error core_c.pas 114:E2003 Undeclared identifier: 'size_t'
estoy compilando con delphi 2010 14.0.3513........
? me pudes dar luces de caual puede ser el error? Osea el sipo size_t
, no esta definido. Donde se define,, De antemano gracias
Responder

You might also like