This is the original image that i took: https://i.stack.imgur.com/MCp9B.jpg
I threshold the image: https://i.stack.imgur.com/hvSND.png
hsv_img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
frame_threshed = cv2.inRange(hsv_img, lower_limit, upper_limit)
And search for rectangles: https://i.stack.imgur.com/1yJXq.png
#return a list of all the detected shapes in the image
contours,_ = cv2.findContours(thresholded_img, cv2.RETR_TREE,
cv2.CHAIN_APPROX_SIMPLE)
#list of all the detected rectangles:
detected_shapes = []
#for every detected shape
for cnt in contours :
approx = cv2.approxPolyDP(cnt, 0.009 * cv2.arcLength(cnt, True), True)
#if the polygon have 4 sides and smaller then the image
if(len(approx) == sides_num) and (detected_shapes_img.shape[0]-1)
(detected_shapes_img.shape[1]-1)> cv2.contourArea(cnt):
detected_shapes.append(approx)
Now i want to extract the 3D orientation and position in relative to the camera 3D orientation and position. like in this exempale. Just remember What that interest me is not that specific image. Is to create a script that can take a image with a ractanguar shape and estimate the shape position and orientation. The only function that do this that i know of is cv2.solvePnP(). But the function Requires camera matrix and distortion coefficients, and i dont know how to get this data. So if you know i can i get those parameters, or you have another solution your it be very helpful.