Getting error

,
I am getting an error as TypeError: Required argument 'rec' (pos 2) not found

My code is as

    sample = images[0].permute(1, 2, 0).cpu().numpy()
    boxes = outputs[0]['boxes'].data.cpu().numpy()
    scores = outputs[0]['scores'].data.cpu().numpy()
    boxes = boxes[scores >= detection_threshold].astype(np.int32)
    fig, ax = plt.subplots(1, 1, figsize=(32, 16))
    for box in boxes:
        cv2.rectangle(img=sample,
                      pt1=(box[0], box[1]),
                      pt2=(box[2], box[3]),
                      color=(220, 0, 0))

ax.set_axis_off()
img = np.array(img)
st.image(cv2.UMat.get(sample), clamp=True)
st.write("# Results")
st.dataframe(pd.DataFrame(results))

My full error as is
TypeError: Required argument โ€˜recโ€™ (pos 2) not found

Traceback:

File "/home/stark/anaconda3/envs/mark/lib/python3.6/site-packages/streamlit/script_runner.py", line 332, in _run_script
    exec(code, module.__dict__)File "/home/stark/streamlit/streamlit.py", line 129, in <module>
    color=(220, 0, 0))

Hi there,

This looks like an issue relating to the opencv cv2.rectangle command, which takes the following positional arguments

cv2.rectangle(image, start_point, end_point, color, thickness)

Can you double check that your box variable is a list containing 4 integer points? The error above seems to be that opencv is looking for either two tuples or a rec object via function overload

Hey @Cells, I changed that sort of code to
for box in boxes:

    cv2.rectangle(sample,
                  (box[0], box[1]),
                  (box[2], box[3]),
                  (220, 0, 0), 2) 

but this error pops up
TypeError: Expected Ptrcv::UMat for argument โ€˜imgโ€™

Traceback:

```
File "/home/stark/anaconda3/envs/mark/lib/python3.6/site-packages/streamlit/script_runner.py", line 332, in _run_script
    exec(code, module.__dict__)File "/home/stark/streamlit/streamlit.py", line 129, in <module>
    (220, 0, 0), 2)
```

Ok this looks like open CV isnโ€™t happy with that sample and could be related to some numpy type issue. Can you try:

cv2.rectangle(
    np.array(sample),
    (box[0], box[1]),
    (box[2], box[3]),
    (220, 0, 0),
    2
)

Yep, it give the same error
TypeError: Expected Ptrcv::UMat for argument โ€˜imgโ€™

Could you click on the previous postโ€™s link to the opencv git hub issue and try the solutions listed there? Namely, sample = sample.copy()

Alternatively, if your sample image is grayscale:

sample = cv2.cvtColor(sample, cv2.COLOR_GRAY2RGB)

If the problem persists, I recommend going to Stack Overflow as youโ€™re more likely to find a solution there :slight_smile:

1 Like

Hey @Cells, I indeed got a result but the rectangle is not mapped to the image
i,e I just got a return of the image, that I uploaded

I got the co-ordinate of the boxes as my output.

Edit: It worked. Thanks sooooooooooooo much.
It took me 4 days to get here. Have a nice day

1 Like