Reputation: 473
l'm a little bit confused on width and height parameter :
Is the height which is the first parameter or the second ?
HEIGHT,WIDTH= img.shape[0:2]
or WIDTH,HEIGHt= img.shape[0:2]
and in resize function height=32 and width=100
or the inverse ?
image=cv2.resize(img, (32, 100), interpolation=cv2.INTER_NEAREST)
Upvotes: 4
Views: 9620
Reputation: 801
It's quite common (for me) to be confused. So, just copy the snippet from now on:
img = cv2.imread('./my_img.png')
resized_img = cv2.resize(img,
(img.shape[1], img.shape[0])
)
# HEIGHT, WIDTH = img.shape[0:2]
# resized_img = cv2.resize(img, (WIDTH, HEIGHT))
constructor of the Size
class
construct function of the Mat
class
Mat(int rows, int cols , int type)
Mat(Size(int cols, int rows), int type)
(x,y)
, or notate as (width,height)
In other words, these access the same point:
mat.at<type>(y,x)
(cpp)your_img_ndarray[y][x]
(python)mat.at<type>(cv::Point(x,y))
(cpp)dsize = Size(round(fx*src.cols), round(fy*src.rows))
1. explicitly specify dsize=dst.size() : fx and fy will be computed from that.
resize(src, dst, dst.size(), 0, 0, interpolation);
(double)dsize.width/src.cols
2. specify fx and fy , let the function compute the destination image size.
resize(src, dst, Size(), 0.5, 0.5, interpolation);
Upvotes: 0
Reputation: 5152
With .shape it's HEIGHT, WIDTH = img.shape[0:2]
. The reason for this, is it's a numpy matrix, where the first value means number of rows, and the second is number of columns.
When you resize it's img = cv2.resize(img, (WIDTH, HEIGHT))
.
Upvotes: 12
Reputation: 48258
You are right, you can verify by yourself... When you do something like:
Mat occludedSquare= imread("p4.jpg");
then you find a matrix like:
but the p4 image is actually: width: 339 high: 372
so OpenCV is associating rows → high and cols → width
Upvotes: 1