Michael Lorenzo
Michael Lorenzo

Reputation: 663

Porting C++ opencv to Python - trouble with array

this is definitely a simple question but I have a mental block and can't put two and two together.

I want to convert this:

cv::Point2f p[4];

to a python equivalent. right now I am using:

q = [(0,0)]*4

Is this correct? or do I need to mimic the struct?

This seems to beworking in terms of being compatible with the usual convention of storing points, however im running into this error "new style getargs format but argument is not a tuple"

Upvotes: 0

Views: 54

Answers (2)

Michael Lorenzo
Michael Lorenzo

Reputation: 663

ok silly answer, and if anyone is looking for this without debugging for another hour without knowing what to look for, the point data are nested inside each array element of q

q = [(0,0)]*4
q[0] = corners[0]
q[0][0] is needed to reference data pulled from here

to create point: ( q[0][0][0] , q[0][0][1] )

EDIT: this is poor form and I find the following is cleaner

q = corners[[idx0, idx1, idx2, ...]] # for q of size 1xN where N = length(corners) 

Upvotes: 0

Gil D.
Gil D.

Reputation: 139

Seems new style getargs format but argument is not a tuple is an error that happens when you pass a number or other object when the library expects a tuple. So I'd wager you have a bug elsewhere, unrelated to this struct.

Upvotes: 1

Related Questions