URLs of interest:
http://www.huge-man-linux.net/man1/opencv-createsamples.html
Learning opencv step by step
- Antonio Linares
- Site Admin
- Posts: 42595
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 38 times
- Been thanked: 86 times
- Contact:
- Antonio Linares
- Site Admin
- Posts: 42595
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 38 times
- Been thanked: 86 times
- Contact:
Re: Learning opencv step by step
Let the magic begin... 
Lets start recognizing "eyes" (also "faces") and later on we will recognize anything (training our own "Haar Cascades").
We select and use a CascadeClassifier, for eyes "haarcascade_eye.xml"
There are a few "false" positives that we can fine tune with these values:
cv::Size( 30, 60 ) where 30 is the smallest size allowed ad 60 is the largest value allowed
cv1.prg modified to recognize "eyes"


Lets start recognizing "eyes" (also "faces") and later on we will recognize anything (training our own "Haar Cascades").
We select and use a CascadeClassifier, for eyes "haarcascade_eye.xml"
There are a few "false" positives that we can fine tune with these values:
cv::Size( 30, 60 ) where 30 is the smallest size allowed ad 60 is the largest value allowed
cv1.prg modified to recognize "eyes"
Code: Select all | Expand
#include "FiveWin.ch"
#define WINDOW_AUTOSIZE 1
function Main()
local hMat := cv_ImRead( "007.jpg" )
cv_namedWindow( "window title", WINDOW_AUTOSIZE )
cv_ImShow( "window title", hMat )
cv_WaitKey()
return nil
#pragma BEGINDUMP
#include <hbapi.h>
#include <opencv.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/imgproc.hpp>
static cv::Mat mat1;
HB_FUNC( CV_IMREAD )
{
cv::CascadeClassifier face_cascade;
std::vector<cv::Rect> faces;
face_cascade.load( "c:/opencv/sources/data/haarcascades/haarcascade_eye.xml" );
mat1 = cv::imread( hb_parc( 1 ) );
face_cascade.detectMultiScale( mat1, faces, 1.1, 3, 0, cv::Size( 30, 60 ) );
for( size_t i = 0; i < faces.size(); i++ )
cv::rectangle( mat1, faces[ i ], cv::Scalar( 255, 255, 255 ), 1, 1, 0 );
hb_retptr( &mat1 );
}
HB_FUNC( CV_NAMEDWINDOW )
{
cv::namedWindow( hb_parc( 1 ), hb_parnl( 2 ) );
}
HB_FUNC( CV_IMSHOW )
{
cv::imshow( hb_parc( 1 ), * ( ( cv::Mat * ) hb_parptr( 2 ) ) );
}
HB_FUNC( CV_WAITKEY )
{
cv::waitKey( hb_parnl( 1 ) );
}
#pragma ENDDUMP

- Antonio Linares
- Site Admin
- Posts: 42595
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 38 times
- Been thanked: 86 times
- Contact:
Re: Learning opencv step by step
Now we simply change "haarcascade_eye.xml" with "haarcascade_frontalface_alt.xml" and we start recognizing faces 
Next... lets recognize anything we want


Next... lets recognize anything we want


- Antonio Linares
- Site Admin
- Posts: 42595
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 38 times
- Been thanked: 86 times
- Contact:
Re: Learning opencv step by step
Instructions to recognize anything we may want:
https://docs.opencv.org/4.5.4/dc/d88/tutorial_traincascade.html
https://docs.opencv.org/4.5.4/dc/d88/tutorial_traincascade.html
To support this tutorial, several official OpenCV applications will be used: opencv_createsamples, opencv_annotation, opencv_traincascade and opencv_visualisation.
Createsamples, traincascade and opencv_haartraining are deprecated
Positive samples are created by the opencv_createsamples application
1. You can generate a bunch of positives from a single positive object image.
2. You can supply all the positives yourself and only use the tool to cut them out, resize them and put them in the opencv needed binary format.
Re: Learning opencv step by step
Excellent, thank you very much for sharing!
Merry Christmas to the whole community.
Merry Christmas to the whole community.
Saludos,
Eduardo
Eduardo
- Antonio Linares
- Site Admin
- Posts: 42595
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 38 times
- Been thanked: 86 times
- Contact:
Re: Learning opencv step by step
Instead of having to train our data and create a XML file ("Haar Cascade") we have found that for images matching it is much simpler to use cv.matchTemplate() as this way we don't need to train any data, we simply search an image inside another image.
We have found two ways of doing this: Using GDI+ or using OpenCV
Thanks to Manuel Alvarez and Cristobal Navarro now we have a new function GDP_IMAGEINTOIMAGE() that uses GDI+.
You can think of it like doing a simple At( "bitmap_to_find.bmp", "larger_bitmap_that_contains_the_previous_bitmap_to_search_for.bmp" )
Using OpenCV we can rotate the "bitmap_to_find.bmp" and find it in any position (90,180,270 degrees), something that GDP_IMAGEINTOIMAGE() does not support yet, though GDI+ can also rotate an image. So we can expect that we are going to have two different ways of searching a bitmap inside a larger bitmap
I see this as a huge progress in bitmaps management
We have found two ways of doing this: Using GDI+ or using OpenCV
Thanks to Manuel Alvarez and Cristobal Navarro now we have a new function GDP_IMAGEINTOIMAGE() that uses GDI+.
You can think of it like doing a simple At( "bitmap_to_find.bmp", "larger_bitmap_that_contains_the_previous_bitmap_to_search_for.bmp" )
Using OpenCV we can rotate the "bitmap_to_find.bmp" and find it in any position (90,180,270 degrees), something that GDP_IMAGEINTOIMAGE() does not support yet, though GDI+ can also rotate an image. So we can expect that we are going to have two different ways of searching a bitmap inside a larger bitmap
I see this as a huge progress in bitmaps management

Re: Learning opencv step by step
Creo que lo de reconocer objetos puede ser un trabajo arduo, no obstante se va a intentar.
He conseguido compilar el ejemplo de Antonio, pero al compilar me arroja los siguientes errores que no se como resolver:
He conseguido compilar el ejemplo de Antonio, pero al compilar me arroja los siguientes errores que no se como resolver:
Code: Select all | Expand
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\ostream(410): warning C4530: Se ha utilizado el controlador de excepciones de C++, pero la semántica de desenredo no está habilitada. Especifique /EHsc
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\ostream(403): note: al compilar la función del miembro clase plantilla "std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(double)"
C:\opencv\build\include\opencv2/core/utility.hpp(400): note: Vea la referencia a la creación de una instancia de la función plantilla "std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(double)" que se está compilando
C:\opencv\build\include\opencv2/core/cvstd.inl.hpp(82): note: Vea la referencia a la creación de una instancia de clase plantilla "std::basic_ostream<char,std::char_traits<char>>" que se está compilando