为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

暮色呼如 2019-09-20 16:13:59
我在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)作为(列,行)
查看完整描述

3 回答

?
ABOUTYOU

TA贡献1812条经验 获得超5个赞

这是一个用于区分python的[row,columns]和OpenCV的[x,y]的可视示例。


import numpy as np

import matplotlib.pyplot as plt

import cv2


img = np.zeros((5,5))  # initialize empty image as numpy array

img[0,2] = 1  # assign 1 to the pixel of row 0 and column 2


M = cv2.moments(img)  # calculate moments of binary image

cX = int(M["m10"] / M["m00"])  # calculate x coordinate of centroid

cY = int(M["m01"] / M["m00"])  # calculate y coordinate of centroid


img2 = np.zeros((5,5))  # initialize another empty image

img2[cX,cY] = 1  # assign 1 to the pixel with x = cX and y = cY


img3 = np.zeros((5,5))  # initialize another empty image

img3[cY,cX] = 1  # inver x and y


plt.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]")


查看完整回答
反对 回复 2019-09-20
  • 3 回答
  • 0 关注
  • 3378 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信