Ask Your Question
0

Image ROI error! (UserWarning: Attempting to set identical bottom==top)

asked 2017-09-08 05:39:47 -0600

Santhosh1 gravatar image

updated 2017-09-08 06:32:17 -0600

Image ROI

I am trying to virtually split the image into blocks using this simple statement given in OpenCV tutorial in the above link.

imgp0 = img[55:55, 110:110]

Such a statement is giving an error saying.

 UserWarning: Attempting to set identical bottom==top results in singular transformations; automatically expanding.bottom=-0.5, top=-0.5'bottom=%s, top=%s') % (bottom, top))

Whenever we give same coordinates for both this error pops up.

Is it an OpenCV issue? If not how can I fix it?

edit retag flag offensive close merge delete

Comments

Its a warning, which is not the same as an error and will thus have no influence on the execution. Basically its saying you that Python given the same x or y coordinate twice will look at [x-0.5,x+0.5] to define the value. This will generate negative values if you hit the 0 border, hence the warning. But in your case it will not generate problems...

StevenPuttemans gravatar imageStevenPuttemans ( 2017-09-09 04:43:43 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-09-08 07:41:21 -0600

updated 2017-09-08 10:19:22 -0600

maybe someone who know python explain better, i tried to show correct usage by the code below.

filename = '../data/messi5.jpg'
img = cv2.imread(filename)

tl_x=280
tl_y = 340
width=60
height=60

ball = img[tl_x:tl_x+width, tl_y:tl_y+height]

new_pos_tl_x=0
new_pos_tl_y = 0

img[new_pos_tl_x:new_pos_tl_x+width, new_pos_tl_y:new_pos_tl_y+height] = ball 

new_pos_tl_x=100
new_pos_tl_y = 100

img[new_pos_tl_x:new_pos_tl_x+width, new_pos_tl_y:new_pos_tl_y+height] = ball
edit flag offensive delete link more

Comments

@sturkmen I mentioned if the X and Y coordinates are the same it pops an error, try it once.

ball = img[280:280, 330:390]

Santhosh1 gravatar imageSanthosh1 ( 2017-09-08 08:59:10 -0600 )edit

i think you can understand well if you try the code in the answer.see also NumPy v1.13 Manual

you can change the values below

tl_x=280 // x of top left of the roi
tl_y = 340 // y of top left of the roi
width=60
height=60
sturkmen gravatar imagesturkmen ( 2017-09-08 10:21:40 -0600 )edit

@sturkmen

Okay, This is what you mean to say.

(x1,y1) --> Top coordinates of the ROI (x2,y2) --> Bottom right corner coordinate of ROI

So the ROI will look like

img[ x1:x2 , y1:y2 ]
Santhosh1 gravatar imageSanthosh1 ( 2017-09-13 06:24:12 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-09-08 05:39:47 -0600

Seen: 2,146 times

Last updated: Sep 08 '17