ESP-Cam: How do I find out the MATCH ID locally on the camera if a face recognition was successful?

337 views
Skip to first unread message

PeterN

unread,
Oct 7, 2020, 10:17:36 AM10/7/20
to Annex WiFi RDS
Hi CiccioCB 
I am experimenting with ESP32_CAM and M5-CAMERA, and I really like it !!!.
  
I use an M5Stack (and your ESP32_dev_board) with its TFT-display as a client running the example code. On the client screen I can mark a recognized face with a rectangle and can print its MATCH_ID which is filtered with TFT.CAMERA$  from the HTTP-header..

But  how can I use the last MATCH_ID on the CAMERA as well?  I do  miss there a variable or an event to get the last face recognition MATCH_ID (and as well the coordinates of the face detection).
Did  I oversee something?  

PeterN 




cicciocb

unread,
Oct 10, 2020, 2:50:17 AM10/10/20
to Annex WiFi RDS
Hi Peter,
sorry for the late answer.
Just found that I forgot to document the function CAMERA.DETECTED$.
This function returns the same information sent in the header.

I'll update the help at the same time for the next release

PeterN

unread,
Oct 10, 2020, 3:15:20 AM10/10/20
to Annex WiFi RDS
Good morning ciccioCB

Fantastic! That is what I hoped for! 
Thanks!!

I played a bit with my M5 devices and ANNEX-Cam:



PS: I could not post a picture or append a file here, because the server refuses the upload.

cicciocb

unread,
Oct 10, 2020, 4:34:56 AM10/10/20
to Annex WiFi RDS
Hi Peter,
I forgot to add that there is also another associated event, ONCAMDETECT

PeterN

unread,
Oct 10, 2020, 4:44:17 AM10/10/20
to Annex WiFi RDS
That really completes the usability!

PeterN

unread,
Oct 10, 2020, 5:22:25 PM10/10/20
to Annex WiFi RDS
Good evening CiccioCB,

I did some successfull testing with face recognition  on the M5camera 
- without a separate client (= other ANNEX32 or a browser-script) looking at the cam-picture and its header 
- but locally using the  OnCamDetect event and then the CAMERA.DETECTED$.
It seems to be a bit tricky to avoid  to have to many detection events, if the cam sees a face. This caused a lot of unwanted freezes and reboots until I temporarily deactivated the face detection to give time to  process the needed actions.   

If someone likes to try that maybe my code can help as a start.

This was the code for my experiment with the M5-camera looking at a set of fotos in a diashow-window at my notebook:


CODE: xxxx.bas

' ##################################################################################
' M5Camera (or ESP32-CAM)  for face recognition 
' Saves the last 7  detected faces in /faces.fh
' Ccompare the currently detected face with the stored fraces
'
'###################################################################################
rate = 10
detection_msg$ = "----"

'The Camera can recognize max 7 faceIDs and stored them in /faces.fh
dim FACE$(7)="PeterN","MonikaN","Obama","Johnson","Trump","Merkel","Face #7"
'dim FACE$(7)="Face #1","Face #2","Face #3","Face #4","Face #5","Face #6","Face #7"

' must set the resolution to 320*240 for facerecognition
print camera.setup(4) '320*240
print camera.params("vflip", 1)
print camera.params("hmirror", 1)

print camera.params("detection",1)
print camera.params("readfaces",1)
print camera.params("recognition",1)

'################################################
OnCamDetect FACE_DETECTED
onHtmlReload setpage
gosub setpage

wait

'###################################################################################
'###################################################################################

setpage:
'----------
cls
a$ = ""
A$ = A$ + |<h2> AnnexCAM Face Recognition</h2>|
A$ = A$ + |<img id='camera' src="picture" alt="AnnexCam" style="width:auto;"><br><br>|
A$ = A$ + "<br><br>"
A$ = A$ + button$("V Flip", v_flip) + button$("H mirror", h_mirror)
A$ = A$ + "<br><br>"
A$ = A$ + button$("ENROLL THE NEXT FACE", ENROLL_FACES) + button$("Save all Faces to /faces.fh", SAVE_FACES)
A$ = A$ + "<br><br>"
A$ = A$ + textbox$(detection_msg$) 

html a$
jscall "set_pictimer(" + str$(rate) + ");"
'autorefresh 250
autorefresh 1000
a$ = ""
return

' ##################################################################################
ENROLL_FACES:
'----------
print camera.params("enroll", 1)
return

'###################################################################################
SAVE_FACES:
'----------
print camera.params("savefaces", 1)
return

'###################################################################################
v_flip:
'----------
v = camera.getvalue("vflip")
print camera.params("vflip", 1 - v)
return

'###################################################################################
h_mirror:
'----------
v = camera.getvalue("hmirror")
print camera.params("hmirror", 1 - v)
return

'###################################################################################

FACE_DETECTED:
'----------
detection_msg$ = Camera.detected$
' Temporarily deactivate the face detection to prevent getting to many detection-events
print camera.params("detection",0)  

'The detected face may be one of the 7 faces stored in /face.fh 
detection_msg$ = word$(detection_msg$, 2, "Match ID:") 
if detection_msg$ <> "" then detection_msg$ = FACE$(val(detection_msg$)) else detection_msg$ = "?????"

refresh
pause 1000

'reactivate face detection  
print camera.params("detection",1)

return



PeterN

unread,
Nov 6, 2020, 10:08:33 AM11/6/20
to Annex WiFi RDS
Hi CiccioCB,

I am still very enthusiastic about ANNEXCAM. 
Could you give more detailed information about the functions that had to be removed for the sake of speed and memory?   

Thanks 
Peter

cicciocb

unread,
Nov 9, 2020, 4:03:01 AM11/9/20
to Annex WiFi RDS
Hi Peter,
this is the list of the functionalities included / removed in the ANNEXCAM.
This table will be included in the documentation.

Functionalities enabled in the ANNEXCAM version


FUNCTIONALITY

ENABLED

TFT display


QRCODE


ESPNOW

PID


ETHERNET


CONVERT

MQTT

OLED


APDS9960


BME280

INFRARED


PLAY (WAV, MP3, VOICE)


NEOPIXEL


VL53L0X


RFID


FREQUENCY METER


IOBUFFER

WDT

MPU9250


MPU6886


MPU6050


FUSION ALGO


BNO055


PCA9685


TM1637 AND TM1638


MAXDISPLAY


PeterN

unread,
Nov 9, 2020, 6:04:14 AM11/9/20
to Annex WiFi RDS
Thanks  Francesco,
I do not see PWM in the table. Is it OK?

cicciocb

unread,
Nov 9, 2020, 6:06:06 AM11/9/20
to Annex WiFi RDS
Hi Peter,
all that is not listed is included by default.
This list could evolve in the future depending on the requests.

PeterN

unread,
Nov 9, 2020, 6:12:59 AM11/9/20
to Annex WiFi RDS
Thanks again, 
I have a X/Y-servo-mount for the ESPCAM  an I plan to try to follow a face with it.

PeterN

unread,
Nov 20, 2020, 1:53:17 AM11/20/20
to Annex WiFi RDS
Hi CiccioCB,
I use face recognition  with an M5CAM. That works fine. You can enroll and recognize  7 faces, but the faces are stored in a kind of  ring buffer memory. So you can not exchange a specific single "old" face at a specific selectable memory position, but only add a new face and thus delete the eldest.  
Do you see a chance to add that kind of  function?

This is what I use at the moment for testing the face recognition:
CODE: xxxx.bas

' ##################################################################################
' M5Camera (or ESP32-CAM)  for face recognition
' Saves the last 7  detected faces in /faces.fh
' Ccompare the currently detected face with the stored fraces
'
'###################################################################################
rate = 30
rate = 10
detection_msg$ = "----"
F$ = "--"
'The Camera can recognize max 7 faceIDs and stored them in /faces.fh
dim FACE$(7)="PeterN","MonikaN","Obama","Johnson","Trump","Merkel","Face #7"
'dim FACE$(7)="Face #1","Face #2","Face #3","Face #4","Face #5","Face #6","Face #7"

' must set the resolution to 320*240 for facerecognition
print camera.setup(4) '320*240
print camera.params("vflip", 1)
print camera.params("hmirror", 1)

print camera.params("detection",1)
print camera.params("readfaces",1)
print camera.params("recognition",1)

'################################################
OnCamDetect FACE_DETECTED
onHtmlReload setpage
gosub setpage

wait

'###################################################################################
'###################################################################################

setpage:
'----------
cls
a$ = ""
A$ = A$ + |<h2> AnnexCAM Face Recognition</h2>|
A$ = A$ + |<img id='camera' src="picture" alt="AnnexCam" style="width:auto;"><br><br>|
A$ = A$ + "<br><br>"
A$ = A$ + textbox$(F$)
A$ = A$ + "<br><br>"
A$ = A$ + button$("V Flip", v_flip) + button$("H mirror", h_mirror)
A$ = A$ + "<br><br>"
A$ = A$ + button$("ENROLL THE NEXT FACE", ENROLL_FACES) + button$("Save all Faces to /faces.fh", SAVE_FACES)

OnCamDetect OFF
' Temporarily deactivate the face detection to prevent getting to many detection-events
'print camera.params("detection",0)

'The detected face may be one of the 7 faces stored in /face.fh
D$ = word$(detection_msg$, 2, "Match ID:")
if D$ <> "" then
  F$= FACE$(val(D$))
else
  F$= "?????"
end if
refresh
pause 1000
F$= "-"
'reactivate face detection
OnCamDetect FACE_DETECTED
'print camera.params("detection",1)
return

cicciocb

unread,
Nov 20, 2020, 12:07:26 PM11/20/20
to Annex WiFi RDS
I think that it could be possible but I must check how do it.

I'll let you know.

Florian Bednarz

unread,
Jan 6, 2021, 8:50:35 AM1/6/21
to Annex WiFi RDS
HI,
i have a 3d printed robot with 2x endless rotation Servos as drives

whenever i want to use PWM.setup the program stops or the esp32-cam is not reachable any more..

here my example code:



'title$ = "Virtual Joystick"
joy$ = "C"
jsexternal "/joy_cb.min.js"

rate = 30 ' rate between each picture sample (msec)
'pause 100
' set the max resolution in terms of memory
if camera.setup(10) = 0 then end
print camera.params("vflip", 1)
print camera.params("hmirror", 1)

'set at 800x600
print camera.params("framesize", 4)



speed = 20
leftservo =295
rightservo = 307
leftcenter = 300
rightcenter =307
PWM.SETUP 13, 1, leftcenter, 50, 12
PWM.SETUP 12, 2, rightcenter, 50, 12



onHtmlReload setpage

gosub setpage

'onHtmlChange input_check

wait

 



setpage:

cls
a$ = ""
a$ = a$ + |<h2>AnnexCAM Demo mini</h2> |
a$ = a$ + |<img id='camera' src="picture" style=width:25%;height:auto;">|

a$ = a$ +  "<br><br>"
'a$=a$ + |<div style='display: table; margin-right: auto; margin-left: auto;'>| + textbox$(title$,"t") + |</div>|+"<br>"
a$=a$ + |<div style='display: table; margin-right: auto; margin-left: auto;'>|
a$=a$ + |<div id="joyDiv" style="width:200px;height:200px;margin-bottom:20px;margin:10px"></div>|
a$=a$ + |<br><div style="display: table; margin-right: auto; margin-left: auto;">| + textbox$(joy$,"t") + |</div>|
a$=a$ + cssid$("t","text-align:center;border-style: none;")
autorefresh 100
html a$

a$ = |joy = new JoyStick('joyDiv');|
a$ = a$ + |joy.SetCallback(function(e) {connection.send('cmd:immediatxJOY$="' + e.GetDir() + '":HtmlEventVar$="joy$"\n' )});|
jscript a$
a$ = ""
jscall "set_pictimer(" + str$(rate) + ");"






return 'setpage


input_check:
if joy$ = "N" then
PWM.out 1, leftcenter - speed
pwm.out 2, rightcenter + speed
end if 'Nord                           'joystick activity returns directions directly into joy$ textbox

if joy$ = "S" then
PWM.out 1, leftcenter + speed
pwm.out 2, rightcenter - speed
end if

if joy$ = "E" then
PWM.out 1, leftcenter - speed
pwm.out 2, rightcenter - speed
end if

if joy$ = "W" then
PWM.out 1, leftcenter + speed
pwm.out 2, rightcenter + speed
end if

if joy$ = "C" then
PWM.out 1, leftcenter
pwm.out 2, rightcenter
end if 'Nord

return 'input_check

ciccio cb

unread,
Jan 6, 2021, 9:21:24 AM1/6/21
to Annex WiFi RDS
The pins 12 and 13 are not available if you are using the SDCARD. 
You should put SDCARD NONE in the config page if you want to use these pins. 

--
You received this message because you are subscribed to the Google Groups "Annex WiFi RDS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to annex_wifi_rd...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/annex_wifi_rds/13ccd9f9-0582-475a-b53e-e8cb2dd0f813o%40googlegroups.com.

Florian Bednarz

unread,
Jan 6, 2021, 2:59:41 PM1/6/21
to Annex WiFi RDS
> To unsubscribe from this group and stop receiving emails from it, send an email to annex_w...@googlegroups.com.
I know, so i disabled the sdcard in config...

Dos still not work...

cicciocb

unread,
Jan 6, 2021, 3:33:38 PM1/6/21
to Annex WiFi RDS
I remember I did that trick (the double servo on the CAM) some time ago but  I used the GPIO12 and the RX pin.

Probably the SPI bus is always initialised in the Annex version that you have.

Florian Bednarz

unread,
Jan 7, 2021, 2:19:33 AM1/7/21
to Annex WiFi RDS
Thanks a lot, i will try differnt pins.
i only used that two pins because the original arduino sketch (and so my add on pcb) used these two pins...

this is the thing i have printed:
but i don´t like the original interface, so i want to build my own with annex basic ;-)

Flo

Florian Bednarz

unread,
Feb 1, 2021, 8:44:29 AM2/1/21
to annex_w...@googlegroups.com
I tried with many different pins: 01,03,12,13
whenever i do 

PWM.SETUP PIN, 1, 150, 50, 12
as mentioned in the Online help 

Annex stops working.
i tried 3 differnt esp32-cam modules from different Vendors...
always the same thing:

Annex output disconnects, no picture is shown and i have to restart the module manually to reach the web editor again...

i tried with every combination in the config screen, enable SD, disable SD etc...


this is my sample code:

Code hier eingeben...rate = 30 ' rate between each picture sample (msec)
pause 100

'when i include this line, no matter what PIN annex-cam stops working...
PWM.SETUP 12, 1, 150, 50, 12



' set the max resolution in terms of memory
if camera.setup(10) = 0 then end

print camera.params("vflip", 0)
print camera.params("hmirror", 0)

'set at 800x600
print camera.params("framesize", 6)

pause 100


onHtmlReload setpage

gosub setpage

wait


setpage:
cls
a$ = ""
'a$ = a$ + |<h2>AnnexCAM Demo mini</h2> |
a$ = a$ + |<br><br> |
a$ = a$ + |<img id='camera' src="picture" style="width:auto;height:25%;transform:rotate(90deg);">|

html a$

Florian Bednarz

unread,
Feb 1, 2021, 5:00:37 PM2/1/21
to Annex WiFi RDS
Found a solution!

if i use PWM channel 3 and 4 instead of 1 and 2 it works perfect!

PWM.SETUP PIN, 3, 150, 50, 12
Reply all
Reply to author
Forward
0 new messages