0
I have a code where I take a video and save an image every 20 frames and I take a slice of that image, until then I was able to do it, but I need to analyze if they have pixels with the same or darker shade of brown than this: RGB 194, 187, 138 and I have no idea how to do this, how to detect percentage of brown color with this specific RGB?
That’s my code so far
import cv2
import os
import numpy as np
# Read the video from specified path
cam = cv2.VideoCapture("D:/outpy.avi")
currentframe = 0
x = 20
while(True):
# reading from frame
ret,frame = cam.read()
if ret:
# if video is still left continue creating images
name = 'D:/' + str(currentframe) + '.png'
print ('Creating...' + name)
# writing the extracted images
if currentframe == x:
cv2.imwrite(name, frame)
imagem = cv2.imread("D:/{}.png".format(x))
fatia = imagem[0:150, 150:300]
x = x + 20
if cv2.waitKey(25) & 0xFF == ord('q'):
break
# increasing counter so that it will
# show how many frames are created
currentframe += 1
else:
break
# Release all space and windows once done
cam.release()
cv2.destroyAllWindows()
See if the following answers help: Calculate percentage of certain colors in an image and Color detection and tell which color is appearing. But note the fact that the Opencv library works in the BGR color space as default, so if the RGB color space is used, perform the conversion with
cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
– danieltakeshi
I had already seen the two links, but I could not solve by the tip they pass on
– Simone
You first need to set a range in some type of color space, for example RGB, or the most recommended HSV. By setting the range of what you consider brown, it’s easy to check... An interval split is the of Soen’s reply
– danieltakeshi