Ask Your Question

DanMaynard's profile - activity

2013-06-07 12:38:26 -0500 received badge  Teacher (source)
2013-06-07 04:15:25 -0500 answered a question Python crop not working

I assume that you would like to crop out a rectangle where the tuples (x1,y1) and (x2,y2) define the corners? Also to be clear, I assume origin at top left, x across and y down.

The [] notation is really array slicing in numpy and not an OpenCV function, so the first pair is rows and the second pair columns. This means you need

crop = vis[y1:y2, x1:x2]

Numpy slicing is very flexible, in general with 'basic slicing' like this it returns a view to the same memory buffer so if you modify crop the values in vis will change. This is probably not a problem here, but if it is you can force a copy easily with

crop = vis[y1:y2, x1:x2].copy()

... although obviously this is slightly slower to run.