Python-Opencv, getting the reigon of image where a color is most dominant?

ساخت وبلاگ
چکیده : i have a piece of code which detects the presence of the color red , i then divided the frame to 2 R... با عنوان : Python-Opencv, getting the reigon of image where a color is most dominant? بخوانید :

i have a piece of code which detects the presence of the color red , i then divided the frame to 2 ROI, and i applied a mask in each of those regions, so i have at the end Ones representing where the color is found and zeroes for the rest and this goes for all regions.

i know what to find the region which has the dominance of red color? how do i do that?

import cv2
import math
import numpy as np

Video = cv2.VideoCapture(0)
while True:
    _, img = Video.read()
    # detect red lines
    # =======================================
    hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
    min = np.array([150, 40, 40])
    max = np.array([190, 255, 255])
    mask = cv2.inRange(hsv, min, max)
    height, width = img.shape[:2]

    res1 = cv2.bitwise_and(img, img, mask=mask)
    #res1= cv2.cvtColor(res1,cv2.COLOR_BGR2GRAY)
    roi1 = res1[0:height, 0:width / 2]
    roi2 = res1[0:height, width / 2:width]

    cv2.imshow("part1", roi1)
    cv2.imshow("part2", roi2)

    k = cv2.waitKey(2) & 0xFF
    if k == 27 or k == 'q':
        break
Video.release()
cv2.destroyAllWindows()

i tried doing this

 roi1 = img[0:height, 0:width / 2]
 roi2 = img[0:height, width / 2:width]
 res1 = cv2.bitwise_and(roi1, roi1, mask=mask)
 res2 = cv2.bitwise_and(roi2, roi2, mask=mask)

but i got an error which is this

res1 = cv2.bitwise_and(roi1, roi1, mask=mask) cv2.error: OpenCV(3.4.2) C:projectsopencv-pythonopencvmodulescoresrcarithm.cpp:241: error: (-215:Assertion failed) (mtype == 0 || mtype == 1) && _mask.sameSize(*psrc1) in function 'cv::binary_op'

i think if there wasn't that error, i could have compared the values of res1 and res2 directly?

back soft...
ما را در سایت back soft دنبال می کنید

نویسنده : استخدام کار بازدید : 6 تاريخ : دوشنبه 19 آذر 1397 ساعت: 20:06