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

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

將變換矩陣應(yīng)用于 OpenCV 中的 warpTransform

將變換矩陣應(yīng)用于 OpenCV 中的 warpTransform

尚方寶劍之說 2021-09-28 13:23:31
因此,我想轉(zhuǎn)換圖像,但無法真正找到使用 OpenCV 進(jìn)行轉(zhuǎn)換的正確方法。我有圖像的第一件事就是說 500x600px 里面有一個扭曲的東西,我想“拉直”看圖像:我正在像這樣獲得數(shù)獨的輪廓:cropped_image, contours, _ = cv2.findContours(cropped_image, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)max_contour = max(contours, key=cv2.contourArea)然后我得到max_contour和圖像極端像素(左上角、右上角、右下角和左下角)并獲取變換矩陣并像這樣變換圖像:x, y = cropped_image.shapeimage_extreme_pixels = np.array([[0, y], [x, y], [x, 0], [0, 0]], dtype=np.float32)c_x, c_y = [], []for i in contour:  c_x.append(i[0][0])  c_y.append(i[0][1])contour_extreme_pixels = np.array([  [min(c_x), max(c_y)],  [max(c_x), max(c_y)],  [max(c_x), min(c_y)],  [min(c_x), min(c_y)]],  dtype=np.float32)t_matrix = cv2.getPerspectiveTransform(contour_extreme_pixels, image_extreme_pixels)transformed_image = cv2.warpPerspective(cropped_image, t_matrix, (y, x))plt.imshow(cropped_image, interpolation='nearest', cmap=plt.cm.gray)但是當(dāng)我查看圖像時,它以一種奇怪的方式發(fā)生了變化。我想拉伸數(shù)獨的頂部,使其輪廓筆直。你能指出我的代碼有什么問題嗎?我假設(shè)這可能是我創(chuàng)建 4 個極端像素的方式,然后將這些像素放入getPerspectiveTransform以獲得轉(zhuǎn)換矩陣,但尚未設(shè)法使其工作。
查看完整描述

2 回答

?
守著一只汪

TA貢獻(xiàn)1872條經(jīng)驗 獲得超4個贊

假設(shè)您已經(jīng)準(zhǔn)確地找到了數(shù)獨的角點,您可以將輸入圖像仿射變換為:


# Hard coded the points here assuming that you already have 4 corners of sudoku image

sudoku_corner_points = np.float32([[235, 40], [1022, 55], [190, 875], [1090, 880]])

canvas = np.ones((500, 500), dtype=np.uint8)

dst_points = np.float32([[0, 0], [500, 0], [0, 500], [500, 500]])


t_matrix = cv2.getPerspectiveTransform(sudoku_corner_points, dst_points)


transformed_image = cv2.warpPerspective(img, t_matrix, (500, 500))

查看完整回答
反對 回復(fù) 2021-09-28
  • 2 回答
  • 0 關(guān)注
  • 245 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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