Ask Your Question

sayem48's profile - activity

2017-05-23 13:58:48 -0600 received badge  Enthusiast
2017-05-18 16:02:09 -0600 asked a question Detected object stuck at the corner of the camera view

I want to write a code which will detect a object, pass a signal to arduino, when the object is out of camera view it will continue to detect the next object. Here is the original post about it : Send a single from Python to Arduino for a range of values (http://stackoverflow.com/questions/43...)

Now, when I use " Code 1", camera detects a object, tracks it, But when detected object is at edge of camera view: detected object freezes at the corner of camera view (detected object does not go out of camera view). If the object returns back into the camera view tracking resumes.

Code 1:

face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
cap = cv2.VideoCapture(0)
while 1:
    ret, img = cap.read()
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    faces = face_cascade.detectMultiScale(gray, 1.3, 5)
    for (x1, y1, w1, h1) in faces:
        cv2.rectangle(img, (x1, y1), (x1 + w1, y1 + h1), (255, 0, 0), 2)
        cv2.imshow('img', img)
cap.release()
cv2.destroyAllWindows()

The debugging shows that when detected face is at the left corner of the image, (x1,y1,w1,h1) at faces is zero and that just stuck there. I want the detected object to move out of the camera view.

How can I unfreeze the detected object and resume fluid flow of objects?

2017-05-03 19:21:33 -0600 asked a question Serial comunication between opencv and arduino

I tried to check if my OpenCV code is communicating with Arduino or not.

OpenCV code:

import numpy as np
import cv2
import serial
import time
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
cap = cv2.VideoCapture(0)
while 1:
ret, img = cap.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x, y, w, h) in faces:
cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
detect=x
print(detect)
cv2.imshow('img', img)
k = cv2.waitKey(30) & 0xff
if k == 27:
break
cap.release()
cv2.destroyAllWindows()
if 0<detect<100 :
ser = serial.Serial("COM1", 19200, timeout=5)  ##  everything else is default
time.sleep(2)
ser.write("\x35")
print "RECIEVED BACK:", repr(ser.read(5000))

Arduino Code

int incomingByte = 0;   
void setup() {
Serial.begin(19200); 
}
void loop() {
if (Serial.available() > 0) {
incomingByte = Serial.read();
// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}
}

When I run OpenCV code; if something is detected; 'detect' always has a value. After I press "Esc" button (close openCV) then I get the return value from arduino:

RECIEVED BACK:I received: 51/r/n

What I want to do is: whenever 'detect' has some value I want to send a signal to arduino to turn a servo. Here is my original post: http://stackoverflow.com/questions/43...

It seems arduino port is somehow jammed and I can't get a continuous communication. My limited knowledge ends there! How can I solve this?

2017-03-24 15:58:30 -0600 asked a question Haar Cascade training for leaves detection

Hi everyone, I am new to this. I am using OpenCV+python at a windows machine. I wanted to know that is there any step by step tutorial for Haar cascade training for OpenCV+Python at a windows machine to create you own .xml file?

Sayem