Define sections in a color recognition program

1

I'm working on a project, which will be my CBT next year. I'm learning from the Python language, and for the time being I've had some progress. I was reading about computer vision, but I still have some doubts. I was able to formalize a program (after many video lessons in English kk) that displays the video of the Webcam, and the tracking of any object with the color blue. I'm having trouble defining sections in this same program. These sections would be to locate whether a part has entered the "home" or not. I'll use this for a game of the old one, so I need to define a 3x3 section (actually a # on the screen), and I can see if an object has entered this house or not. Here's the code I have for now. If anyone has any idea how to do this would be of great help!

import cv2   
import numpy as np

cap=cv2.VideoCapture(0)

while(1):
    ret, img = cap.read()

#converter imagem(img i.e BGR) para HSV (hue-saturation-value)

hsv=cv2.cvtColor(img,cv2.COLOR_BGR2HSV)

#definir dimensão da cor Azul
blue_lower=np.array([99,115,150],np.uint8)
blue_upper=np.array([110,255,255],np.uint8)

#encontrar as dimensões da cor Azul
blue=cv2.inRange(hsv,blue_lower,blue_upper)

#transformação e processamento  
kernal = np.ones((5 ,5), "uint8")

blue=cv2.dilate(blue,kernal)
res1=cv2.bitwise_and(img, img, mask = blue)

#Tracking da cor azul
(_,contours,hierarchy)=cv2.findContours(blue,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
for pic, contour in enumerate(contours):
    area = cv2.contourArea(contour)
    if(area>300):
        x,y,w,h = cv2.boundingRect(contour) 
        img = cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
        cv2.putText(img,"Blue color",(x,y),cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255,0,0))


cv2.imshow("Cor",img)   
k = cv2.waitKey(30) & 0xFF
if k==27:
    break

    cap.release()
    cv2.destroyAllWindows()
    
asked by anonymous 28.07.2018 / 01:54

0 answers