OpenCV Point(x,y)表示(列,行)或(行,列)

我在Matrix src中有300 * 200的图像。我正在对图像进行以下操作。


for(int i=0;i<src.rows;i++){

for(int j=0;j<src.cols;j++){

line( src, Point(i,j),Point(i,j), Scalar( 255, 0, 0 ),  1,8 );

}

]

imshow("A",src);

waitKey(0);

我期待它以白色覆盖整个图像,但图像的下半部分仍然是空的。如果我这样做的话


  for(int i=0;i<src.rows;i++){

    for(int j=0;j<src.cols;j++){

    src.at<uchar>(i,j)=255;

    }

    ]

    imshow("A",src);

    waitKey(0);

整个图像覆盖白色。所以,这意味着src.at(i,j)使用(i,j)作为(行,列),但Point(x,y)使用(x,y)作为(列,行)


暮色呼如
浏览 3368回答 3
3回答

ABOUTYOU

这是一个用于区分python的[row,columns]和OpenCV的[x,y]的可视示例。import numpy as npimport matplotlib.pyplot as pltimport cv2img = np.zeros((5,5))&nbsp; # initialize empty image as numpy arrayimg[0,2] = 1&nbsp; # assign 1 to the pixel of row 0 and column 2M = cv2.moments(img)&nbsp; # calculate moments of binary imagecX = int(M["m10"] / M["m00"])&nbsp; # calculate x coordinate of centroidcY = int(M["m01"] / M["m00"])&nbsp; # calculate y coordinate of centroidimg2 = np.zeros((5,5))&nbsp; # initialize another empty imageimg2[cX,cY] = 1&nbsp; # assign 1 to the pixel with x = cX and y = cYimg3 = np.zeros((5,5))&nbsp; # initialize another empty imageimg3[cY,cX] = 1&nbsp; # inver x and yplt.figure()plt.subplot(131), plt.imshow(img, cmap = "gray"), plt.title("With [rows,cols]")plt.subplot(132), plt.imshow(img2, cmap = "gray"), plt.title("With [x,y]")plt.subplot(133), plt.imshow(img3, cmap= "gray"), plt.title("With [y,x]")
打开App,查看更多内容
随时随地看视频慕课网APP