This is my first topic in the forum and there is a subject I struggled a lot while doing lots of testing to apply the feature I want with opencv in python.
# This gives the coordinates of the detected objects' bbox coordinates what is in my for loop
y1 = (int(box[i,0]*height))
x1 = (int(box[i,1]*width))
y2 = (int(box[i,2]*height))
x2 = (int(box[i,3]*width))
# After that I say here "if the detected object is a car and its ID is 1, then blend the image on the webcam frame
if classes[0][i] == 3 and i == 1:
(x_center,y_center) = (x2 + x1)/2, (y2 + y1)/2
added_image_2 = cv2.addWeighted(frame[: , x1:y1, :],alpha,img[:,75:75,:],1-alpha,0) # img[0:75,0:75,:] img[0:100,0:100,:]
frame[y1:y2+75 , x1:x2+75] = added_image_2
However, I always get this error:
added_image_2 = cv2.addWeighted(frame[: , x1:y1, :],alpha,img[:,75:75,:],1-alpha,0) # img[0:75,0:75,:] img[0:100,0:100,:]
cv2.error: OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-q0nmoxxv\opencv\modules\core\src\arithm.cpp:669: error: (-209:Sizes of input arguments do not match) The operation is neither ‘array op array’ (where arrays have the same size and the same number of channels), nor ‘array op scalar’, nor ‘scalar op array’ in function ‘cv::arithm_op’
Before this, I applied this feature I want with mouse coordinate successfully with this line of codes:
# Select the region in the background where we want to add the image and add the images using cv2.addWeighted()
added_image = cv2.addWeighted(frame[mouseY:mouseY+img_height , mouseX:mouseX+img_width,:],alpha,img[0:100,0:100,:],1-alpha,0) # img[0:75,0:75,:]
# Change the region with the result
frame[mouseY:mouseY+img_height , mouseX:mouseX+img_width] = added_image
and this is the result of it:
What I want this to insert / add this image on where the detected object for ID is 1
I have taken to apply a different concept, thanks to this tutorial example from here:
add-image-to-a-live-camera-feed-using-opencv-python/
If anyone would guide me how to solve this issue I will be very glad, thank you very much.