rvecs and tvecs are NoneType?

asked 2019-01-27 09:59:28 -0500

czjczjczj1 gravatar image

updated 2019-01-27 10:47:29 -0500

I saw some python codes online for detecting aruco markers, and I combined them together. This is the code: https://github.com/czjczjczj1/aruco/b...

I wanted to draw the x-, y-, z-axis too, but I got an error saying:
for i in range(len(tvecs)):
TypeError: object of type 'NoneType' has no len()

So why rvecs and tvecs are NoneType? How can I get two arrays?

edit retag flag offensive close merge delete

Comments

this means, your tvecs array is empty, it probably did not detect any marker before.

for further help, please EDIT your question. we need to see, how you try to detect the marker(s), code, example image, etc.

berak gravatar imageberak ( 2019-01-27 10:02:34 -0500 )edit

@supra56@berak It's still not working. It said
for i in range(0, tvecs): TypeError: 'NoneType' object cannot be interpreted as an integer
Even I added something like
for i in range(0, 2):
it said
frame_axis_image = cv2.aruco.drawAxis(frame_detected_markers.copy(), mtx, dist, rvecs[i], tvecs[i], 0.05) TypeError: 'NoneType' object is not subscriptable

czjczjczj1 gravatar imageczjczjczj1 ( 2019-01-27 10:58:39 -0500 )edit

please check:

 frame_detected_markers == None

(https://github.com/czjczjczj1/aruco/b...)

berak gravatar imageberak ( 2019-01-27 11:03:44 -0500 )edit

@czjczjczj1. I just deleted it. I will rephase it. You cannot used len function to draw line. I f you want to draw a line , then us cv2.line.

supra56 gravatar imagesupra56 ( 2019-01-27 11:05:09 -0500 )edit

it seems, that the 1st thing python noobs have to learn is:

you have to check the outcome of every single line of your code

(blindly copypasting shit is never an option !)

berak gravatar imageberak ( 2019-01-27 11:08:45 -0500 )edit

@czjczjczj1 Does this help? cv2.aruco.drawAxis(frame instead of cv2.aruco..drawAxis(frame_detected_markers.copy()

Also don't forget cv2.imshow('frame', frame)

supra56 gravatar imagesupra56 ( 2019-01-27 11:22:25 -0500 )edit

I don't think it's None.

czjczjczj1 gravatar imageczjczjczj1 ( 2019-01-27 11:46:42 -0500 )edit

I know I'm silly, then what should I do?

czjczjczj1 gravatar imageczjczjczj1 ( 2019-01-27 12:07:03 -0500 )edit

@czjczjczj1. There is nothing wrong with ur code. I attempted from link. The reasoning why you getting an errored TypeError: object of type 'NoneType' has no len(), is because you need to add boolean for both. if ids is not None and len(ids) > 0:. Btw, I'm using linux.

supra56 gravatar imagesupra56 ( 2019-01-27 22:58:54 -0500 )edit

It's working now, thank you very much for your help. By the way, it seems that the z-axis is not vertical to the marker. Why is that? @supra56 I would like to know the 3D distance between two markers, is this possible?

czjczjczj1 gravatar imageczjczjczj1 ( 2019-01-28 05:07:17 -0500 )edit