# image ROIs in python

What are the numbers in the the bracket? Are they rows and columns of the pixel matrix.Also how come the person know the exact position to copy the image of a ball inside of an image as for that you would have to be very accurate down to the pixel.

This is in the opencv-python tutorial below is the link. "Here I am selecting the ball and copying it to another region in the image:

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

img[273:333, 100:160] = ball "

Here is the link of the tutorial:http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_core/py_basic_ops/py_basic_ops.html#basic-ops

Go to Image ROI

Thanks :)

edit retag close merge delete

Sort by » oldest newest most voted

As for the first question - 280:340, 330:390 means: get a rectangle that begins at 280th row and 330th column and ends at 340th row and 390 column. Another way to put it: it is a rectangle described by 4 vertices whose coordinates are: (280,330), (280,390), (340,330), (340,390).

In general, this 'i:j' means range from i-th to j-th element.

As for the ball: if you look closely, the author doesn't care about the exact position of the ball - it's been copied together with the grassy background. How did the author know where is the ball? Well, by looking at the image - there is no automatic detection here if this is what you are asking about. The tutorial states that the ball was selected (manually), not detected.

more

Ok i got your point but suppose i want to copy a portion of an image how do i pinpoint the coordinates(it may not be exact). Are you saying this is only possible through trail and error? Thanks for the answer

P.S. i know my questions are silly but why does it get downvoted?

( 2017-07-13 03:13:18 -0500 )edit

I'm not saying the only way to do it is through trial and error - automatic detection is just not described in this chapter. There are many techniques that let you detect objects, but there is no general rule how to do it and which method you choose depends on the type of object, picture quality, color model used and many other factors.

I think you got downvoted because people think you could've found answer to your question easily in the web and you didn't show the minimum effort to do it. I agree with them regarding the first part of your question - it's easy to google it.

( 2017-07-13 03:28:31 -0500 )edit

Not to be too picky on your wording but the indexing for vectors is i:j means from i to j-1. I.e. h, w = img.shape[:2]; print((img[0:h, 0:w] == img).all()) # True while h and w are beyond the indices of the image.

( 2017-07-13 04:07:46 -0500 )edit

Right, forgot to write that.

( 2017-07-13 11:04:23 -0500 )edit

Official site

GitHub

Wiki

Documentation