Tags:
tag this topic
create new tag
view all tags
---+ People Detection ---++ Introduction In this example we use a pre-trained model to find out if a person is in sight of the camera, installed on our esp32-cam board. Before starting the project we must make sure that the camera is working and that we can read images from it. <img alt="esp32cam.png" height="337" src="%ATTACHURL%/esp32cam.png" title="esp32cam.png" width="371" /> The pre-trained model uses 96x96 pixel gray scale images as its input (features), which means that we must be able to read this type of image from the ov2640 camera on the esp-cam board. It turns out that this is pretty simple and below you can find a !MicroPython script reading such an image and saving it to a file <i>camImage.raw o</i>n the ESP32 filesystem on its 4MByte flash. <verbatim># Reads a 96x96 pixel gray scale image from the camera in raw mode # This image can directly be passed into the input tensor of the # person detection model # The program is part of a course on AI and edge computing at the # University of Cape Coast, Ghana # Copyright (c) U. Raich [2022] # The program is released under the MIT License import sys import camera from utime import sleep_ms try: camera.init(0,format=camera.GRAYSCALE,framesize=camera.FRAME_96X96) except: print("Error when initializing the camera") sys.exit() buf=camera.capture() print("type: ", type(buf), " Length: ",len(buf)) # save the raw image to a file print("Writing the data to camImage.raw") if len(buf) == 96*96: f = open("camImage.raw","w+b") f.write(buf) f.close() camera.deinit()</verbatim> <br />Once we have a saved image we can transfer it to the PC via the serial connection and display it there. The simple shell script below transfers the raw image file. It requires [[https://github.com/dhylands/rshell][rshell ]]to be installed on the PC. <verbatim>#!/bin/sh rshell cp /pyboard/camImage.raw .</verbatim> Finally the image can be displayed on the PC using the script below: <verbatim>#!/usr/bin/python3 from PIL import Image import io,sys if len(sys.argv) != 2: print("Usage %s filename"%sys.argv[0]) sys.exit() image_data_file = open (sys.argv[1], 'rb') image_data = bytearray(9612) image_data_file.readinto(image_data) image_data_file.close() image = Image.frombytes ('L', (96,96), bytes(image_data) ,'raw') image.show() </verbatim> -- %USERSIG{UliRaich - 2022-01-31}% ---++ Comments %COMMENT%
Attachments
Attachments
Topic attachments
I
Attachment
History
Action
Size
Date
Who
Comment
png
esp32cam.png
r3
r2
r1
manage
184.0 K
2022-02-21 - 16:14
UliRaich
E
dit
|
A
ttach
|
Watch
|
P
rint version
|
H
istory
: r2
<
r1
|
B
acklinks
|
V
iew topic
|
Ra
w
edit
|
M
ore topic actions
Topic revision: r2 - 2022-02-21
-
UliRaich
Home
Site map
AFNOG web
Embedded_Systems web
IoT_Course_English web
IoT_Course_French web
Main web
Sandbox web
TWiki web
IoT_Course_English Web
Create New Topic
Index
Search
Changes
Notifications
RSS Feed
Statistics
Preferences
P
View
Raw View
Print version
Find backlinks
History
More topic actions
Edit
Raw edit
Attach file or image
Edit topic preference settings
Set new parent
More topic actions
Account
Log In
Register User
E
dit
A
ttach
Copyright © 2008-2025 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback