Face Detect for FWH64

Face Detect for FWH64

Postby CharlesKwon » Sat Dec 04, 2021 2:22 am

Hello All.

I just finished a facial recognition program available on fwh64.
Previously, I used several 3rd party facial recognition SDK, but with the recent development of AI programs, it was written with pure FWH64 and OpenCV(C++)

FWH Power!

Regards,
Charles KWON


sample image
http://www.kugya.com/result.jpg

Image

Code: Select all  Expand view  RUN


#include "fivewin.ch"

#define IMREAD_COLOR 1

FUNCTION Main()  
    LOCAL oDlg
    LOCAL oImage
    LOCAL cFile := "test4.jpg"

    DEFINE DIALOG oDlg TITLE "DrFace c)Charles KWON"

           @ 0,0 IMAGE oImage FILE cFile OF oDlg

           oDlg:bStart := {|| doFaceDetect( oDlg, cFile, oImage )  }

    ACTIVATE DIALOG oDlg CENTER
   
RETURN NIL


FUNCTION doFaceDetect( oDlg, cFile, oImage )
    LOCAL pImg := 0
    LOCAL pImg2
    LOCAL pStr := ""
    LOCAL pStr2 := ""
    LOCAL oCV2    
    LOCAL nFaces
    LOCAL aFaces := {}

    oImage:Move(0,0,oImage:nWidth, oImage:nHeight, .t.)
    oDlg:Move(0,0,oImage:nWidth, oImage:nHeight, .t.)
    oDlg:Center()

    oCv2 := TCV2():New()
   
    IF !oCv2:imread( cFile, IMREAD_COLOR, @pImg )
       RETURN .F.
    ENDIF

    IF !oCv2:DetectFaces( pImg, @nFaces, @aFaces )
       oCv2:DeleteObject( pImg )
       RETURN .F.
    ENDIF

    oImage:bPainted := {| hDC | oCv2:DrawFaces( hDC, aFaces ) }  
    oImage:Refresh()


RETURN .T.



 
User avatar
CharlesKwon
 
Posts: 28
Joined: Sun Nov 02, 2014 7:03 am

Re: Face Detect for FWH64

Postby Antonio Linares » Sat Dec 04, 2021 6:21 am

Dear Charles,

You are a Master, since very long time ago.

Could you share the libs, etc. required to build your example ?

thank you so much,
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42118
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Face Detect for FWH64

Postby CharlesKwon » Sat Dec 04, 2021 6:38 am

Sure why not! dear my bro.

Now I Implement Face Matching functions Using Deep Learning.
I'll open 100% source code for FWH users ASAP.
I review all of OpenCV source codes and I finding UNDOCUMENTED datas for FWH

And It is part of code for face detect and face feature extract.

Code: Select all  Expand view  RUN

HB_FUNC( DETECTFACES )
{
  Mat* img = static_cast<Mat *>( hb_parptr(1) );
  PHB_ITEM nCount = hb_param(2,HB_IT_ANY);
  PHB_ITEM aFaces = hb_param(3,HB_IT_ARRAY);
  PHB_ITEM aFeatures = hb_param(4,HB_IT_ARRAY);

  PHB_ITEM Subarray  = hb_itemNew(NULL);
  PHB_ITEM cTemp     = hb_itemNew(NULL);
  uchar * ucData ;
   
  Mat image1 = img->clone();
  String fd_modelPath = "yunet.onnx";
  String fr_modelPath = "face_recognizer_fast.onnx";
 
  bool save = false ;
  double cosine_similar_thresh = 0.363;
  double l2norm_similar_thresh = 1.128;
     
  TickMeter tm;  

  tm.start();

  //! [inference]
  // Set input size before inference
  detector->setInputSize(image1.size());

  Mat faces1;
  detector->detect(image1, faces1);

  if (faces1.rows < 1)
  {    
    hb_itemPutNI( nCount, 0 );
    hb_retl(false);
    return ;
  }

  tm.stop();

  hb_itemPutNI( nCount, faces1.rows );  

  for (int i = 0; i < faces1.rows; i++)
  {
   
      hb_arrayNew( Subarray, 4 );

      hb_arraySetNInt( Subarray, 1, int(faces1.at<float>(i, 0) ));
      hb_arraySetNInt( Subarray, 2, int(faces1.at<float>(i, 1) ));
      hb_arraySetNInt( Subarray, 3, int(faces1.at<float>(i, 2) ));
      hb_arraySetNInt( Subarray, 4, int(faces1.at<float>(i, 3) ));

      hb_arrayAddForward( aFaces, Subarray );
  }

  /*
    feature extract
  */
 
  Mat aligned_face1 ;  
  Mat feature1;
 
  for (int i = 0; i < faces1.rows; i++)
  {
    faceRecognizer->alignCrop(image1, faces1.row(i), aligned_face1);
    faceRecognizer->feature(aligned_face1, feature1);
    feature1 = feature1.clone();
    ucData = feature1.data;
    hb_arrayAddForward( aFeatures , hb_itemPutC( cTemp, (const char *) ucData) );  
  }
 
  hb_retl(true);

}

 
User avatar
CharlesKwon
 
Posts: 28
Joined: Sun Nov 02, 2014 7:03 am

Re: Face Detect for FWH64

Postby Otto » Sat Dec 04, 2021 10:58 am

Hello Charles,
WOW, respect and congratulations.
And thank you so much for sharing.
Best regards,
Otto

PS: Could it be that the most left is the main actor of the Netflix series "Start up"?
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6336
Joined: Fri Oct 07, 2005 7:07 pm

Re: Face Detect for FWH64

Postby CharlesKwon » Sun Dec 05, 2021 4:25 pm

Hello Otto

Thank you for your kind comment.

Today, I just finished a very important function like the attached one.
Now We can found a face landmark and drawing it.


Regards,
Charles KWON

http://www.kugya.com/result2.jpg
User avatar
CharlesKwon
 
Posts: 28
Joined: Sun Nov 02, 2014 7:03 am

Re: Face Detect for FWH64

Postby richard-service » Mon Dec 06, 2021 12:39 am

CharlesKwon wrote:Hello All.

I just finished a facial recognition program available on fwh64.
Previously, I used several 3rd party facial recognition SDK, but with the recent development of AI programs, it was written with pure FWH64 and OpenCV(C++)

FWH Power!

Regards,
Charles KWON


sample image
http://www.kugya.com/result.jpg

Image

Code: Select all  Expand view  RUN


#include "fivewin.ch"

#define IMREAD_COLOR 1

FUNCTION Main()  
    LOCAL oDlg
    LOCAL oImage
    LOCAL cFile := "test4.jpg"

    DEFINE DIALOG oDlg TITLE "DrFace c)Charles KWON"

           @ 0,0 IMAGE oImage FILE cFile OF oDlg

           oDlg:bStart := {|| doFaceDetect( oDlg, cFile, oImage )  }

    ACTIVATE DIALOG oDlg CENTER
   
RETURN NIL


FUNCTION doFaceDetect( oDlg, cFile, oImage )
    LOCAL pImg := 0
    LOCAL pImg2
    LOCAL pStr := ""
    LOCAL pStr2 := ""
    LOCAL oCV2    
    LOCAL nFaces
    LOCAL aFaces := {}

    oImage:Move(0,0,oImage:nWidth, oImage:nHeight, .t.)
    oDlg:Move(0,0,oImage:nWidth, oImage:nHeight, .t.)
    oDlg:Center()

    oCv2 := TCV2():New()
   
    IF !oCv2:imread( cFile, IMREAD_COLOR, @pImg )
       RETURN .F.
    ENDIF

    IF !oCv2:DetectFaces( pImg, @nFaces, @aFaces )
       oCv2:DeleteObject( pImg )
       RETURN .F.
    ENDIF

    oImage:bPainted := {| hDC | oCv2:DrawFaces( hDC, aFaces ) }  
    oImage:Refresh()


RETURN .T.



 


Dear Kwon,

Good job.
Best Regards,

Richard

Harbour 3.2.0dev (r2402101027) => Borland C++ v7.7 32bit
MySQL v8.0 /ADS v10
Harbour 3.2.0dev (r2011030937) => Borland C++ v7.4 64bit
User avatar
richard-service
 
Posts: 804
Joined: Tue Oct 16, 2007 8:57 am
Location: New Taipei City, Taiwan

Re: Face Detect for FWH64

Postby cmsoft » Mon Dec 06, 2021 11:24 am

Excelente trabajo! Muy agradecido por tu aporte.
Voy a investigarlo... Es de muchisima utilidad!
User avatar
cmsoft
 
Posts: 1291
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina

Re: Face Detect for FWH64

Postby Silvio.Falconi » Mon Dec 06, 2021 3:27 pm

WHERE IS
Code: Select all  Expand view  RUN
oCv2 := TCV2():New()   ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7070
Joined: Thu Oct 18, 2012 7:17 pm

Re: Face Detect for FWH64

Postby albeiroval » Tue Dec 07, 2021 2:41 am

Dear Charles,

Congratulations, I hope to use your code soon.
Thank you.
Saludos,
Regards,

Albeiro Valencia
www.avcsistemas.com
User avatar
albeiroval
 
Posts: 379
Joined: Tue Oct 16, 2007 5:51 pm
Location: Barquisimeto - Venezuela

Re: Face Detect for FWH64

Postby Antonio Linares » Tue Dec 07, 2021 8:11 am

OpenCV: Organizing with Charles its implementation in FWH 64 bits (it requires 64 bits):

https://youtu.be/p9IsfqNewmE

https://opencv.org/

https://github.com/opencv/opencv

It works perfectly fine with FWH 64 bits :-)

Thanks to Charles for his R+D research and sharing !!!
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42118
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Face Detect for FWH64

Postby sygecom » Tue Dec 07, 2021 11:48 am

Caso alguém tenha interesse, o coleta Marcos Antonio Gambeta desenvolveu um LIB para usar recursos da OpenCV, ele continua evoluindo com a mesma.

O arquivo abaixo contém a versão corrente da biblioteca para OpenCV:
https://www.mediafire.com/file/6l92au1o ... om.7z/file

O arquivo inclui também o BCC, xHarbour e HWGUI. Daí o tamanho grande.
Se tiver problemas para baixar, me avise que procuro colocar em outro local.

Depois de baixar, descompacte na unidade C. Você terá uma pasta chamada ‘opencv_sygecom’.

Entre nela e execute o !prompt.bat com um clique duplo.

No prompt, entre na pasta ‘hbopencv2’ e depois na pasta ‘tests’:

cd hbopencv2
cd tests

Compile o test1.prg conforme abaixo:

compile test1

Execute assim:

test1 caosorvete.jpg

Compile o test2.prg conforme abaixo:
compile_hwgui test2

Execute assim:
test2

Deve mostrar uma janela com a câmera e botões para:

capturar uma imagem
exibir a última imagem capturada
fechar a janela

Ao usar a opção de exibir a imagem, feche a janela pressionando uma tecla.

E confira também se a câmera desliga ao fechar o teste. Num dos testes aqui, a câmera continuou ligada e o teste correndo em segundo plano, mesmo com o comando de fechar. Mas pode ter sido um evento isolado. De qualquer forma, está na lista de pendências verificar isto.

Há arquivos .bat para gerar o código-fonte, compilar a biblioteca e importar as bibliotecas do OpenCV.
Há funções interessantes para implementar, mas preciso estudá-las melhor, pois trabalham com callbacks’s. Planejo ver isto o mais breve possível.


Segue o link para uma atualização do projeto:
https://www.mediafire.com/file/bm7n9gk9 ... 33.7z/file

Agora é possível usar o terceiro parâmetro da função cvSaveImage, para controlar alguns parâmetros da imagem. Veja o test3.prg.
Sempre que se usar a função cvLoadImage, é importante liberar a imagem com cvReleaseImage. Os testes foram corrigidos neste sentido.
Se a imagem for obtida com cvQueryFrame, NÃO DEVE SER LIBERADA. Deixe por conta do OpenCV.
User avatar
sygecom
 
Posts: 55
Joined: Tue Mar 11, 2008 3:18 am
Location: Brasil

Re: Face Detect for FWH64

Postby Antonio Linares » Wed Dec 08, 2021 6:54 am

Who wants to try it ? Quien quiere probarlo ? :-)

https://github.com/FiveTechSoft/drface

(c) Mr. Charles Kwon

makefiles based on hbmk2 developed by FiveTech
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42118
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Face Detect for FWH64

Postby Baxajaun » Tue Dec 14, 2021 10:25 am

Good morning !!!

Playing with another image.

Image

Image

Image


Thanks !

Regards,
User avatar
Baxajaun
 
Posts: 968
Joined: Wed Oct 19, 2005 2:17 pm
Location: Gatika. Bizkaia

Re: Face Detect for FWH64

Postby Antonio Linares » Tue Dec 14, 2021 3:15 pm

Hopefully quite soon we can train our own neuronal networks with our data :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42118
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Face Detect for FWH64

Postby elvira » Thu Mar 10, 2022 9:49 pm

hi,

I get these errors:

Any clue please?
Code: Select all  Expand view  RUN

Lines 5660, Functions/Procedures 10
Generating C source output to 'C:\Users\Lenovo\AppData\Local\Temp\hbmk_dlk0df.dir\TOpenCV.c'... Done.
TDrFace.c
TOpenCV.c
TOpenCV.prg(163): warning C4189: 'l2norm_similar_thresh': la variable local se ha inicializado pero no se hace referencia a ella
TOpenCV.prg(161): warning C4189: 'save': la variable local se ha inicializado pero no se hace referencia a ella
TOpenCV.prg(162): warning C4189: 'cosine_similar_thresh': la variable local se ha inicializado pero no se hace referencia a ella
TOpenCV.prg(215): warning C4244: 'argumento': conversi¢n de 'float' a '_Tp'; posible p‚rdida de datos
        with
        [
            _Tp=int
        ]
TOpenCV.prg(215): warning C4244: 'argumento': conversi¢n de 'float' a '_Tp'; posible p‚rdida de datos
        with
        [
            _Tp=int
        ]
TOpenCV.prg(216): warning C4244: 'argumento': conversi¢n de 'float' a '_Tp'; posible p‚rdida de datos
        with
        [
            _Tp=int
        ]
TOpenCV.prg(216): warning C4244: 'argumento': conversi¢n de 'float' a '_Tp'; posible p‚rdida de datos
        with
        [
            _Tp=int
        ]
TOpenCV.prg(410): warning C4189: 'l2norm_similar_thresh': la variable local se ha inicializado pero no se hace referencia a ella
TOpenCV.prg(408): warning C4189: 'save': la variable local se ha inicializado pero no se hace referencia a ella
TOpenCV.prg(409): warning C4189: 'cosine_similar_thresh': la variable local se ha inicializado pero no se hace referencia a ella
TOpenCV.prg(399): warning C4189: 'cTemp': la variable local se ha inicializado pero no se hace referencia a ella
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\ostream(411): 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 (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\ostream(404): 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
TOpenCV.prg(356): warning C4505: "visualize": se ha quitado la funci¢n sin referencia con vinculaci¢n interna
Generando c¢digo...
hbmk2: Construyendo sub-proyecto (nivel 2): opencvlib.hbp
hbmk2: Encontrado archivo .lib con formto COFF con el mismo nombre, se recurre
       a usar ‚ste en lugar de la .dll.
Harbour 3.2.0dev (r2006301601)
Copyright (c) 1999-2020, https://harbour.github.io/
Compiling 'opencv.prg'...


Lines 5108, Functions/Procedures 2
Generating C source output to 'C:\Users\Lenovo\AppData\Local\Temp\hbmk_hz5nwk.dir\opencv.c'... Done.
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384

Copyright (C) Microsoft Corporation.  All rights reserved.


opencv.c

hbmk2: Error: Funci¢n(es) referenciada, no encontrada, pero desconocida:
       CVIMSHOW(), TEST_DARK()

 
elvira
 
Posts: 516
Joined: Fri Jun 29, 2012 12:49 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot], MaxP and 50 guests