Ask Your Question
0

Iterate points for OpenCV's Line function

asked 2011-07-02 06:37:39 -0600

Kirielson gravatar image

I'm trying to iterate from two tuples to create a line connection previous points to currents points.

    for (x,y) in currFeatures and (px,py) in self.prev_draw_features:
            cv.line(new_image, (px,py),(x,y),cv.RGB(125, 20,200),5)

Which then leads me to this error:

[ERROR] [WallTime: 1309631642.294530] bad callback: <bound method="" cached_subscriber.callback="" of="" <__main__.cached_subscriber="" instance="" at="" 0x2bbb290="">> Traceback (most recent call last): File "/opt/ros/diamondback/stacks/ros_comm/clients/rospy/src/rospy/topics.py", line 563, in _invoke_callback cb(msg) File "**", line 70, in callback for (x,y) in currFeatures and (px,py) in self.prev_draw_features: NameError: global name 'px' is not defined

Is it possible to iterate between two tuples at the exact same time, or will I need to construct a new variable to iterate between the elements. Keep in mind that the tuples may not be equal (which probably negates my "and" statement.

Thanks.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2011-07-02 13:20:16 -0600

fergs gravatar image

updated 2011-07-02 13:22:42 -0600

What you probably want is:

for ((x,y), (px,py)) in zip(currFeatures, self.prev_draw_features):
        cv.line(new_image, (px,py),(x,y),cv.RGB(125, 20,200),5)
edit flag offensive delete link more

Comments

Okay I did try that but then I got the error: File "****", line 73, in callback cv.line(new_image, (px,py),(x,y),cv.RGB(125, 20,200),5) TypeError: <unknown> is not a numpy array Would I need to first extract all of the information out then re-insert it in?
Kirielson gravatar image Kirielson  ( 2011-07-02 14:23:21 -0600 )edit
How do you get "new_image"? I think that is the only parameter that has to be a numpy array.
fergs gravatar image fergs  ( 2011-07-03 04:56:16 -0600 )edit
I get new image from a live feed camera.
Kirielson gravatar image Kirielson  ( 2011-07-05 01:46:57 -0600 )edit
Okay I got it fixed thanks!
Kirielson gravatar image Kirielson  ( 2011-07-05 05:33:40 -0600 )edit
Could you post how you fixed it for the benefit of future users?
fergs gravatar image fergs  ( 2011-07-05 08:20:55 -0600 )edit
Yeah I will.
Kirielson gravatar image Kirielson  ( 2011-07-06 07:10:48 -0600 )edit
0

answered 2011-07-06 07:15:31 -0600

Kirielson gravatar image

I fixed it with two things,

First it's cv.Line not cv.line

Second of all, this is how you would want to do the listing:

for i in range(min(len (currFeatures), len (self.prev_draw_features))): # Find out which index is shorter
    currpoint = currFeatures[i]
    currpoint = (int(currpoint[0]), int(currpoint[1])) #Also code out the same setup for prev_draw_features
    cv.Line(new_image, currpoint, prevpoint, 123, 5)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-07-02 06:37:39 -0600

Seen: 1,489 times

Last updated: Jul 06 '11