Good day, I am new in IOT field. Allow me to ask some question. I am planning to design a smart obejct which could tracking human face by using Openmv M7 and 360 high speed parallax servo motor. The function of servo motor is to rotate the smart object until it is facing the centre of human face. Only one face will be detected at the same time. For now, my Arduino UNO gained the information of the rectangle drawn on the human face in string form. How to get only the x coordinate and the width of the rectangle drawn in order to find its centre? As I will design a pair of artificial eyes to provide feedback to user, Arduino UNO is needed. Any solution could be provided to help in my project? The script attached is the coding I am using currently. Thanks for helping.
In OpenMV IDE:
import sensor, time, image, pyb
from pyb import UART
uart = UART(3, 9600, timeout_char = 1000)
# Reset sensor
sensor.reset()
# Sensor settings
sensor.set_contrast(1)
sensor.set_gainceiling(16)
# HQVGA and GRAYSCALE are the best for face tracking.
sensor.set_framesize(sensor.HQVGA)
sensor.set_pixformat(sensor.GRAYSCALE)
# Load Haar Cascade
# By default this will use all stages, lower satges is faster but less accurate.
face_cascade = image.HaarCascade("frontalface", stages=25)
print(face_cascade)
# FPS clock
clock = time.clock()
while (True):
clock.tick()
# Capture snapshot
img = sensor.snapshot()
# Find objects.
# Note: Lower scale factor scales-down the image more and detects smaller objects.
# Higher threshold results in a higher detection rate, with more false positives.
objects = img.find_features(face_cascade, threshold=0.75, scale_factor=1.25)
# Draw objects
for a in objects:
img.draw_rectangle(a)
print(str(a))
uart.write(str(a))
uart.write('\n')
In Arduino UNO:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
void getline(char *buffer, int max_len)
{
uint8_t idx = 0;
char c;
do
{
if(idx >= max_len) return;
while (mySerial.available() == 0) ; // wait for a char this causes the blocking
c = mySerial.read();
buffer[idx++] = c;
}
while (c != '\n' && c != '\r');
if(idx >= max_len) return;
buffer[idx] = 0;
}
void setup() {
Serial.begin(9600);
mySerial.begin(9600);
}
void loop(){
char buffer [63+1];
int max_len = 63;
getline(buffer, max_len);
Serial.print(buffer);
}