久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

OpenCV 中的圖像轉換

Image transformation in OpenCV(OpenCV 中的圖像轉換)
本文介紹了OpenCV 中的圖像轉換的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

這個問題與這個問題有關: 函數.我寫了一個快速腳本來展示如何做到這一點.如您所見,這在 Python 中非常簡單.這是測試圖片:

這是變形后的結果:

這里是代碼:

導入 cv2從 scipy.interpolate 導入網格數據將 numpy 導入為 npgrid_x, grid_y = np.mgrid[0:149:150j, 0:149:150j]目的地 = np.array([[0,0], [0,49], [0,99], [0,149],[49,0],[49,49],[49,99],[49,149],[99,0],[99,49],[99,99],[99,149],[149,0],[149,49],[149,99],[149,149]])源 = np.array([[22,22], [24,68], [26,116], [25,162],[64,19],[65,64],[65,114],[64,159],[107,16],[108,62],[108,111],[107,157],[151,11],[151,58],[151,107],[151,156]])grid_z = griddata(目標,源,(grid_x,grid_y),方法='cubic')map_x = np.append([], [ar[:,1] for ar in grid_z]).reshape(150,150)map_y = np.append([], [ar[:,0] for ar in grid_z]).reshape(150,150)map_x_32 = map_x.astype('float32')map_y_32 = map_y.astype('float32')orig = cv2.imread("tmp.png")扭曲 = cv2.remap(原始,map_x_32,map_y_32,cv2.INTER_CUBIC)cv2.imwrite("warped.png", 扭曲)

我想你可以用谷歌搜索一下 griddata 是做什么的.簡而言之,它進行插值,在這里我們使用它來將稀疏映射轉換為密集映射,因為 cv2.remap 需要密集映射.我們只需要將值轉換為 float32,因為 OpenCV 抱怨 float64 類型.請告訴我進展如何.

更新:如果你不想依賴Scipy,一種方法是在你的代碼中實現2d插值功能,例如看Scipy中griddata的源代碼或更簡單的像這樣 http://inasafe.readthedocs.org/en/latest/_modules/engine/interpolation2d.html 僅依賴于 numpy.不過,我建議為此使用 Scipy 或其他庫,盡管我明白為什么只需要 CV2 和 numpy 對于這樣的情況可能會更好.我想聽聽您的最終代碼如何解決數獨問題.

This question is related to this question: How to remove convexity defects in sudoku square

I was trying to implement nikie's answer in Mathematica to OpenCV-Python. But i am stuck at the final step of procedure.

ie I got the all intersection points in square like below:

Now, i want to transform this into a perfect square of size (450,450) as given below:

(Never mind the brightness difference of two images).

Question: How can i do this in OpenCV-Python? I am using cv2 version.

解決方案

Apart from etarion's suggestion, you could also use the remap function. I wrote a quick script to show how you can do this. As you see coding this is really easy in Python. This is the test image:

and this is the result after warping:

And here is the code:

import cv2
from scipy.interpolate import griddata
import numpy as np

grid_x, grid_y = np.mgrid[0:149:150j, 0:149:150j]
destination = np.array([[0,0], [0,49], [0,99], [0,149],
                  [49,0],[49,49],[49,99],[49,149],
                  [99,0],[99,49],[99,99],[99,149],
                  [149,0],[149,49],[149,99],[149,149]])
source = np.array([[22,22], [24,68], [26,116], [25,162],
                  [64,19],[65,64],[65,114],[64,159],
                  [107,16],[108,62],[108,111],[107,157],
                  [151,11],[151,58],[151,107],[151,156]])
grid_z = griddata(destination, source, (grid_x, grid_y), method='cubic')
map_x = np.append([], [ar[:,1] for ar in grid_z]).reshape(150,150)
map_y = np.append([], [ar[:,0] for ar in grid_z]).reshape(150,150)
map_x_32 = map_x.astype('float32')
map_y_32 = map_y.astype('float32')

orig = cv2.imread("tmp.png")
warped = cv2.remap(orig, map_x_32, map_y_32, cv2.INTER_CUBIC)
cv2.imwrite("warped.png", warped)

I suppose you can google and find what griddata does. In short, it does interpolation and here we use it to convert sparse mappings to dense mappings as cv2.remap requires dense mappings. We just need to convert to the values to float32 as OpenCV complains about the float64 type. Please let me know how it goes.

Update: If you don't want to rely on Scipy, one way is to implement the 2d interpolation function in your code, for example, see the source code of griddata in Scipy or a simpler one like this http://inasafe.readthedocs.org/en/latest/_modules/engine/interpolation2d.html which depends only on numpy. Though, I'd suggest to use Scipy or another library for this, though I see why requiring only CV2 and numpy may be better for a case like this. I'd like to hear how your final code solves Sudokus.

這篇關于OpenCV 中的圖像轉換的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 国产精品国产三级国产aⅴ无密码 | 女同久久另类99精品国产 | 精品国产伦一区二区三区观看体验 | 精精国产xxxx视频在线播放 | 中文字幕国产在线 | 亚洲一区二区在线播放 | 免费一级黄色录像 | 综合激情久久 | 欧美日韩大片 | 在线看亚洲 | 亚洲免费精品 | 国产成人jvid在线播放 | 国产精品国产三级国产aⅴ浪潮 | 日韩欧美黄色 | 91精品国产综合久久婷婷香蕉 | 在线观看国产h | 亚洲国产一区二区三区在线观看 | 瑟瑟免费视频 | 一区二区福利视频 | 国产主播第一页 | 亚洲国产精品成人综合久久久 | 99视频在线免费观看 | 一区二区在线 | 可以在线看的黄色网址 | 欧美日韩在线免费观看 | 久久精品日产第一区二区三区 | 成人天堂噜噜噜 | 成人免费视频在线观看 | 美女在线观看国产 | 精品乱码一区二区三四区 | 亚洲精品黄| 精品视频网 | 午夜精品在线 | 一区二区三区国产 | 亚洲视频在线免费观看 | 国产欧美日韩视频 | 国产91精品久久久久久久网曝门 | 亚洲成人一区 | av一二三区 | 亚洲国产一区二区在线 | 国产在线视频一区 |