0

I am new to OpenCv and numpy and I have a problem figuring out how OpenCv indexing works

so first I am reading an image using this piece of code

import cv2
img = cv2.imread(im_address)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
print("img size is {}".format(img.shape))

and the output is

(1280, 960)

where 1280 is the height and 960 is the width,but when I try to draw a line in the image using following line I get a vertical line except a horizontal line

cv2.line(img, (98, 0), (98, 1279), (0, 0, 125), 2)
cv2.namedWindow('image', cv2.WINDOW_NORMAL)
cv2.resizeWindow('image', 700, 500)
cv2.imshow("image", img)
cv2.waitKey(0)
cv2.destroyAllWindows()

does OpenCv treat the first index of any coordinate as width? or I am missing something?

Saro
  • 87
  • 2
  • 12

1 Answers1

1

Yes, OpenCV treats the first and second coordinates as horizontal and vertical respectively. Specifically, the first coordinate traverses the columns and the second traverses the rows.

rayryeng
  • 102,964
  • 22
  • 184
  • 193
  • tnks, I was a little confused because img type is numpy.ndarray – Saro Aug 24 '19 at 19:09
  • @salmanrezaie Yeah, this is a result of keeping with their `cv::Mat` type. The nomenclature there is to do width, height. NumPy arrays do height, width. – rayryeng Aug 24 '19 at 19:24