Mostrando entradas con la etiqueta OpenCV. Mostrar todas las entradas
Mostrando entradas con la etiqueta OpenCV. Mostrar todas las entradas

Seguimiento de personas, animales y objetos con OpenCV en Delphi




OpenCV para los que no la conozcan, es una biblioteca libre enfocada hacia la visión artificial, inicialmente desarrollada por Intel bajo licencia BSD lo que permite que sea usada libremente para un propósito comercial o de investigación.






OpenCV es multiplataforma con versiones para Windows, Linux y Mac y contiene funciones que tratan los temas de proceso de visión, reconocimiento facial, calibrado de cámaras o robótica.


Esta biblioteca es la base de la herramienta Swistrack que sirve para hacer un seguimiento de personas, animales y objetos.





El siguiente código 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 rodeándolas con un rectángulo de color rojo a medida que se van desplazando.




(* /*****************************************************************
// 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
// ****************************************************************
// 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
//
// 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, 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);
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.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);
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.















Reconocimiento de caras con Delphi





Software de reconocimiento de caras ( face recognition ) en imágenes con formato bmp.



Lo que hace es enmarcar cada rostro detectado dentro de un rectángulo utilizando funciones de una dll llamada VCOpenCV.


VCOpenCV se basa en OpenCV (Open Computer Vision) que es una biblioteca de funciones relacionadas con visión artificial  y que como curiosidad se ha utilizado en el sistema de visión del vehículo no tripulado del "Gran desafío DARPA"

Actualmente es un área de investigación muy compleja que necesita la participación de investigadores de diferentes ámbitos, ya que involucra no sólo o programadores e ingenieros de software, sino que también necesita la colaboración de neurocientíficos y psicólogos.




Debido a que estos sistemas son poco intrusivos, aún permanecen en primera línea de investigación por encima de otros como pueden ser los sistemas biométricos, de detección de huellas o reconocimiento del iris.






Descargar codigo fuente




En caso de que nos interese detectar zonas más específicas como ojos y boca, 

tendremos que hacerlo como indica el programa del que abajo os adjunto el link




Descargar codigo fuente




Descargar OpenCV.pas




Descargar OpenCV.pas (Es la traducción de las cabeceras de Opencv en Delphi realizada por Vladimir Vasilyev)





Además me gustaría recordarles que si quieren iniciarse en la programación con Delphi pueden utilizar una versión totalmente gratuita llamada Delphi Starter Edition que la pueden descargar desde aquí.
 




Libros



Face-Detection and Gesture Recognition for Human-computer interaction

Intelligent Biometric Techniques in Fingerprint and Face Recognition (International Series on Computational Intelligence)

Handbook of Face Recognition






















Simulación del movimiento de los electrones en un campo electrico

Espectacular simulación realizada con OpenGL del movimiento de los electrones cuando atraviesan un campo eléctrico. Como muestra la image...