从python中的图像中提取任意矩形块
有没有办法从图像中提取我选择的矩形,也许使用numpy数组?
大多数可用的实现似乎适用于常规的滑动窗口解决方案,但它们总是包含相同宽高比的步骤或矩形,或类似的东西。
Is there a way to extract a rectangle of my choice from an image, maybe using numpy arrays? Most implementations available seem to be for regular sliding window solutions, but those always include steps, or rectangles of the same aspect ratio, or something like that.
是否可以提供开始的x和y坐标以及宽度和高度(或结束x和y坐标),并准确提取该矩形?这可以单独使用numpy数组吗?还是有另一种方法可以做到这一点吗?
Is it possible to provide the beginning x and y coordinates and the width and height (or ending x and y coordinates), and extract exactly that rectangle? Can this be done using numpy arrays alone? Or is there another way to do this?
最好的方法就是切片即
rect = np.copy(img[y1:y1+height,x1:x1+width])
其中(x1,y1)是矩形的左上角。
where (x1, y1) is the upper left corner of your rectangle.