1

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.

liad inon
  • 243
  • 1
  • 12
  • With such a small target and low accuracy edge fitting, you won't get any significant pose information. –  Aug 24 '20 at 18:49
  • If I can take the picture with a better camera and with higher resolution It will be better? I just want a algorithm to use. – liad inon Aug 24 '20 at 18:58
  • It must be significantly better. –  Aug 24 '20 at 19:21
  • If you can send my a explanation of what kind of camera is good and what bad it be helpful. But what im realy need is how to get the camera matrix and distortion coefficient from my camera. – liad inon Aug 24 '20 at 19:31
  • 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. – liad inon Aug 24 '20 at 19:42
  • Here is a good tutorial to find your [camera matrix and associated parameters](https://medium.com/@omar.ps16/stereo-3d-reconstruction-with-opencv-using-an-iphone-camera-part-ii-77754b58bfe0) – DrBwts Aug 25 '20 at 14:43

0 Answers0