Setting Custom RoI For OpenCV BoundryBox In Python

- 1 answer

I'm trying to implement Object Tracker using OpenCV and I'm new to Python. I'll call it from C# code via IronPython. What I'm trying to do, I want to set a custom rectangle as a parameter to Tracker instead of selecting it by mouse.

(Tracker code is the common example you can find on the internet)

Here is the problematic part :

This is how I set and create a rectangle

    initBB = cv2.rectangle(frame ,(154, 278),(173,183), (0, 255, 00),1)

This is Tracker's init method

tracker.init(frame, initBB)

and this is the error

SystemError: new style getargs format but argument is not a tuple

If I wanted to use "normal" way, initBB set would be like

        initBB = cv2.selectROI("Frame", frame, fromCenter=False,

I couldn't see which part I'm doing wrong, am I trying to set the wrong type of object to initBB or setting it in wrong way?

Thanks! Have a nice day!



Your error comes from a misunderstanding of what cv2.rectangle does.

It doesn't return a rectangle as you imagine. It is actually a drawing function. It draws the rectangle on the image you pass as argument and returns None.

A rectangle is just a tuple in Python with the following coordinates: (start_col, start_row, width, height). You can create it without using an OpenCV function.