поиск объекта, определение контуров
Необходимо сделать цикл который выводит "ДА" когда кружочек Ydot, или сам угол квадрата Ydot находятся внутри обозначенной какой то фигуры Sector1. я понимаю что каждый пиксель имеет 5 значений как местоположение и цвет по РГБ, но как заставить код сравнивать только местоположение ничего не смог сделать или найти. Вот код:
#import modules
import cv2
import numpy as np
#Haar's cascade == Face
faceCascade = cv2.CascadeClassifier(r'C:\Users\nu tut vot put'\Lib\site-packages\cv2\data\haarcascade_frontalface_default.xml')
#Open stream of video/images, set the width(3) and height(4) of output window
cv2.namedWindow("webcam")
videostream = cv2.VideoCapture(0)
videostream.set(3,640)
videostream.set(4,480)
#if True (have the matrix of video) read this matrix == got it in bufer
if videostream.isOpened():
window, frame = videostream.read()
else: #if False we'll have no window opened == no cycling more
window = False
#while window is opycle ened(previous code is working) we create Window "window"
while window:
cv2.imshow("webcam", frame) #window is boolean to keep cycle running
window, frame = videostream.read()
frame = cv2.flip(frame, 1)
key = cv2.waitKey(1) #waitKey is function to wait to press 'ESC' to may code pass
if key == 27:
print (a)
print (sector1)
break
#ROI = matrix = part of Frame matrix
pts1 = np.array([[0,0],[320,0],[320,120],[200,240],[0,240]], np.int32)
sector1 = cv2.polylines(frame,[pts1],True,(150,255,255))
sector2 = cv2.rectangle(frame, (0,0), (400,400), (200, 200, 0))
sector1 = np.array(sector1, dtype=np.uint8)
sector2 = np.array(sector2, dtype=np.uint8)
#create faces = Haar's cascade algoritm == Face
faces = faceCascade.detectMultiScale(frame, scaleFactor=1.2, minNeighbors=5, minSize=(20, 20))
for (x,y,w,h) in faces: #FOR will draw cv2.rect when Haar's cascade see the face == Face is in Frame
xdot = x, y
ydot = x+w, y+h
lroi = cv2.rectangle(frame,(xdot),(ydot),(255,50,0),1)
a = cv2.circle(frame, ydot, 2, (0, 0, 200))
#if waitKey pass code destroy everything and end programm
videostream.release()
cv2.destroyWindow('webcam')
Ответы (1 шт):
Автор решения: Никита Иванов
→ Ссылка
Короч жаль что никто не помог, долго мучился, но нашел ответ. Вместо того чтобы запихивать значения пикселей в массивы и т.д. в конце просто задал точку через Х и У и сравнил значение своих плавающих переменных. Все свелось к математике.