Ask Your Question
0

object position tracking, openCV-Python

asked 2018-05-28 12:34:28 -0500

M_F gravatar image

updated 2018-05-29 03:05:17 -0500

I have some sheet on a conveyor belt, with a camera positioned above a corner of the sheet,I have to detect the position ,recognizing the corner compared to the cartesian axes (x, y),and i have to measure the distance between the origin of cartesian axes and my corner. Do you have any advice on the method to use or on which technique i have to rely? I thought to recognize the angle, through the 90 ° angle that is formed between one side of the sheet and the other, but I do not know how to do it.image description

edit retag flag offensive close merge delete

Comments

are you halfway able to detect the corner of your object already ?

show us, what you've tried so far !

berak gravatar imageberak ( 2018-05-29 03:26:28 -0500 )edit

i am trying with this code,but i am unable to recognizie the only corner,instead the whole edge, can you help me? I am not yet a expert.

import numpy as np import cv2 img=cv2.imread('rett.jpg') edges=cv2.Canny(img,100,100) img2,contours,hierarchy=cv2.findContours(edges,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) cv2.drawContours(img,contours,-8,(242,72,0),3) cv2.imshow('img',img) cv2.imshow('img2',img2)

M_F gravatar imageM_F ( 2018-05-29 04:44:31 -0500 )edit

121/5000 thanks for your help, do you have any advice to give me, because I can not detect the only corner but the whole edge?

M_F gravatar imageM_F ( 2018-05-29 05:09:36 -0500 )edit

again, the boundingrect should give you the corner.

maybe you also need to filter the contours, and take only the largest, RETR_EXTERNAL might also be better than RETR_TREE, there is some experimenting involved here !

berak gravatar imageberak ( 2018-05-29 05:13:41 -0500 )edit

OK,THANKS!

M_F gravatar imageM_F ( 2018-05-29 05:17:13 -0500 )edit

1 answer

Sort by » oldest newest most voted
0

answered 2018-05-29 04:54:26 -0500

berak gravatar image

so, if you have the contour already, you can get the boundingbox:

(x,y,w,h) = cv2.boundingRect(contours[0]) # assuming, there is only one contour

from there, it's a straight L2 norm:

pt = (x, y+h) # bottom-left of the obj
orig = (img.shape[1], img.shape[0]); ## bottom-right of the img

dist = math.sqrt( (pt[0]-orig[0])**2 + (pt[1]-orig[1])**2 )
edit flag offensive delete link more

Comments

background segmentation might be helpful, too !

berak gravatar imageberak ( 2018-05-29 05:02:57 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-05-28 12:34:28 -0500

Seen: 1,266 times

Last updated: May 29 '18