I am currently working on a project where I detect a face with a haar cascade classifier. In the code, I have created Rois with a cv2 rectangle and the goal is to apply images to the ROI. On some images the code works on others it doesn´t, also applying filters doesn´t work on videos or on my webcam.
The Error Code: ValueError:
could not broadcast input array from the shape (50,70,3) into shape (50,2,3)
Here are some code lines that may be important:
#Reading the image
image = file dialog.askopenfilename(initialdir="/Pictures", title="select a file", filetypes=(("png files", ".jpg", ),("all file", ".*")))
img = cv2.imread(image)
gray = np.array(img)
How the Roi is created and the filter applied.
visual_eye_r = cv2.rectangle(grayef, (x,y), (x+w, y+h), (255, 255, 255, 0), )
ROI_2 = visual_eye_r[y:y+h, x:x+w]
imagefilter = cv2.imread("filter.png")
roi_h, roi_w = ROI_2.shape[:2]
image_h, image_w = imagefilter.shape[:2]
#Calculate height and width offsets
height_off = int((roi_h - image_h)/2)
width_off = int((roi_w - image_w)/2)
#Mit Numpy Slicing Bild überlegen
ROI_2[height_off:height_off+image_h, width_off:width_off+image_w] = image8
Have already looked elsewhere for the same issue but none of the fixes worked. Maybe someone can help me understand or fix the issue, because i am relative new to python.