Ask Your Question
0

cv2.rectangle missing one side

asked 2020-01-03 00:13:14 -0600

Athen gravatar image

updated 2020-11-07 11:57:13 -0600

please help me out... I'm trying to draw a rectangle using the cv2.rectangle method and one side of the rectangle is not drawn.

test = cv2.imread('warped_example.jpg')
cv2.rectangle(test,(871,700),(1071,560),(0,255,0), 2)
plt.imshow(out_img)

C:\fakepath\opencv.jpg

edit retag flag offensive close merge delete

Comments

try to zoom image

LBerger gravatar imageLBerger ( 2020-01-03 02:50:35 -0600 )edit

increase lineSize for large images

berak gravatar imageberak ( 2020-01-03 02:56:52 -0600 )edit
1

Apparently, the viewer uses nearest neighbour interpolation as default, which often causes surprises. Using some other method would be adviseable.

mvuori gravatar imagemvuori ( 2020-01-03 03:32:31 -0600 )edit

I noticed that you started bottom that is x, y(871, 700), then move up to x1, y1(1071, 560). The y2 is wrong, it is offset by x1, y1. But y1 is wrong. I suggest you start from top to bottom x, y(871, 560) and x1, y1(1071, 700). The (871,700),(1071,560),(0,255,0), 2) is refer to cv2.line. not cv2.rectangle.

supra56 gravatar imagesupra56 ( 2020-01-03 04:43:33 -0600 )edit

As @LBerger, @berak, @mvuori are wrong, They do not understand command cv2.rectangle.The (1071,560) is offset and doesn't return to location of y.

supra56 gravatar imagesupra56 ( 2020-01-03 04:50:57 -0600 )edit

@supra56 no need to such an unnecessary comment above

sturkmen gravatar imagesturkmen ( 2020-01-03 05:01:00 -0600 )edit

1 answer

Sort by » oldest newest most voted
0

answered 2020-01-03 06:52:19 -0600

LBerger gravatar image

May be I'm wrong but I can reproduce problem :

import cv2
from matplotlib import pyplot as plt
test = cv2.imread("F:/Images/20150618_185237.jpg") #image size is 4128X3196
test[:,:,0]=test[:,:,2]
test[:,:,1]=test[:,:,2]
t = cv2.rectangle(test,(871,700),(1071,560),(0,255,0), 2)
plt.imshow(test)
plt.show()

Now results are : no rectangle, a weird rectangle and full rectangle.
image description image description image description

Sometimes problem origin could be multiple...

edit flag offensive delete link more

Comments

@LBerger. This not what we expected in your images. We wanted to see original image from @Athen. Then we can draw rectangle at bottom. He is using some cv2.canny or whatever.. What if you draw rectangle at bottom?

supra56 gravatar imagesupra56 ( 2020-01-03 07:24:35 -0600 )edit

@Athen . Can you post original image not from screenshot?

supra56 gravatar imagesupra56 ( 2020-01-03 07:40:49 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-01-03 00:13:14 -0600

Seen: 1,912 times

Last updated: Jan 03 '20