亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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 關注
  • 3545 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號