Hello,
I am currently working on a project where I want to use my webcam and the colors detected to make a display using an Arduino. I’m at the point where I want to figure out color detection.
My initial thought process is to select a select group of pixels using a for loop, as written out below. I intend to detect the most prominent color in the cropped section and then transfer that information into an array from which I will later pull the color.
import cv2
import numpy as np
webcam = cv2.VideoCapture(0)
# web cam is 640x480, so I'm trying to get 480x480
x=80
y=0
sizeCrop = 48
# Dividing the original video in 4 parts by slicing the frame array
while True :
photo = webcam.read()[1] # Storing the frame in a variable photo
photo = cv2.flip(photo,1) # Fliping the photo for mirror view
hsvFrame = cv2.cvtColor(photo, cv2.COLOR_BGR2HSV)
cv2.imshow('frame', hsvFrame)
for y in range (0, 481, 48) :
for x in range(80, 561, 48):
photo = webcam.read()[1]
photo = cv2.flip(photo,1)
hsvFrame = cv2.cvtColor(photo, cv2.COLOR_BGR2HSV)
cv2.imshow('frame', hsvFrame)
crop = hsvFrame[y:y+sizeCrop, x:x+sizeCrop]
cv2.imshow("current crop", crop) # It will show crop part in a window
if cv2.waitKey(50) == 13 : # Specifying (Enter) button to break the loop
break
y=0
x=80
if cv2.waitKey(50) == 13 : # Specifying (Enter) button to break the loop
break
cv2.destroyAllWindows() # To destroy all windows
I’m not the best at OpenCV-Python, and I sort of just jumped into this project. I would love to hear if anyone has any ideas on how I could approach this part of the project more simplistically, as my method of cropping the live webcam is not working.
Currently, the issue is the loop doesn’t continue. After it runs through all the pixels once the windows close.
As a beginner, I would also really appreciate any resources anyone could relay if you think they may help my current problems.
Thank you in advanced!