第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

cv2 折線無法在 numpy 數(shù)組上繪制“參數(shù) 'img' 的預(yù)期 Ptr<cv::UMat>”

cv2 折線無法在 numpy 數(shù)組上繪制“參數(shù) 'img' 的預(yù)期 Ptr<cv::UMat>”

FFIVE 2023-07-18 16:35:09
我正在將圖像和一系列點的 pytorch 張量表示形式轉(zhuǎn)換為 numpy,以便我可以在點之間繪制線條并在 jupyter lab 中顯示圖像(使用 matplotlib)如果我注釋掉該cv2.polylines行,該代碼將按預(yù)期工作,并向我顯示圖像。    # convert img tensor to np    img = img / 2 + 0.5    img = img.detach().cpu().numpy().astype(np.float32)    img = np.transpose(img, (1, 2, 0))    print(type(img))    # prints:    # <class 'numpy.ndarray'>        # convert label tensor to numpy ndarray    pts = lbl.detach().cpu().numpy().reshape(-1, 1, 2)    pts = np.rint(pts).astype(np.int32)    print([pts])    # prints:    # [array([[[ 17, 153]],    #        [[153, 154]],    #        [[159, 692]],    #        [[ 14, 691]]], dtype=int32)]        # draw lines between the vertices in pts    cv2.polylines(img, [pts], True, (0,255,255))    # show the image with matplotlib.pyplot    plt.imshow(img)    plt.show()但是折線給出了錯誤:---> 36         cv2.polylines(img, [pts], True, (0,255,255))     37         plt.imshow(img)     38         plt.show()TypeError: Expected Ptr<cv::UMat> for argument 'img'如何在該圖像上繪制線條?
查看完整描述

1 回答

?
紫衣仙女

TA貢獻1839條經(jīng)驗 獲得超15個贊

解決方案是復(fù)制圖像

img = img.copy()

看起來 Tensor.numpy() 實際上為您提供了底層數(shù)據(jù)結(jié)構(gòu)的不可變視圖,因此您可以顯示它但不能修改它。要修改它,我必須創(chuàng)建自己的副本


查看完整回答
反對 回復(fù) 2023-07-18
  • 1 回答
  • 0 關(guān)注
  • 173 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號