Ask Your Question
-2

image ROIs in python

asked 2017-07-13 02:18:05 -0600

AA gravatar image

updated 2017-07-13 02:27:09 -0600

berak gravatar image

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 flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2017-07-13 02:55:27 -0600

KjMag gravatar image

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.

edit flag offensive delete link more

Comments

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?

AA gravatar imageAA ( 2017-07-13 03:13:18 -0600 )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.

KjMag gravatar imageKjMag ( 2017-07-13 03:28:31 -0600 )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.

alkasm gravatar imagealkasm ( 2017-07-13 04:07:46 -0600 )edit

Right, forgot to write that.

KjMag gravatar imageKjMag ( 2017-07-13 11:04:23 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-07-13 02:18:05 -0600

Seen: 1,495 times

Last updated: Jul 13 '17