我正在使用 python 上的 opencv 進行透視轉換。所以我使用 SIFT 檢測器找到了兩組點之間的單應矩陣。現在,我想使用 cv2.warperspective 函式轉換影像,但結果證明扭曲影像的質量非常低。
我做了一些谷歌搜索,發現這個,
uj5u.com熱心網友回復:
您是否測驗了 OpenCV 支持的各種插值方法?我認為雙線性或雙三次插值(即INTER_LINEAR或INTER_CUBIC)的結果會讓您感到驚訝。您可以按如下方式更改代碼(實際上您正在使用INTER_NEAREST可以扭曲影像內容):
warpedImg = cv2.warpPerspective(picture, homography_matrix, (w,h), flags= cv2.WARP_FILL_OUTLIERS cv2.INTER_LINEAR)
來自 OpenCV 源代碼:
enum InterpolationFlags{
/** nearest neighbor interpolation */
INTER_NEAREST = 0,
/** bilinear interpolation */
INTER_LINEAR = 1,
/** bicubic interpolation */
INTER_CUBIC = 2,
/** resampling using pixel area relation. It may be a preferred method for image decimation, as
it gives moire'-free results. But when the image is zoomed, it is similar to the INTER_NEAREST
method. */
INTER_AREA = 3,
/** Lanczos interpolation over 8x8 neighborhood */
INTER_LANCZOS4 = 4,
/** Bit exact bilinear interpolation */
INTER_LINEAR_EXACT = 5,
/** Bit exact nearest neighbor interpolation. This will produce same results as
the nearest neighbor method in PIL, scikit-image or Matlab. */
INTER_NEAREST_EXACT = 6,
/** mask for interpolation codes */
INTER_MAX = 7,
/** flag, fills all of the destination image pixels. If some of them correspond to outliers in the
source image, they are set to zero */
WARP_FILL_OUTLIERS = 8,
/** flag, inverse transformation
For example, #linearPolar or #logPolar transforms:
- flag is __not__ set: \f$dst( \rho , \phi ) = src(x,y)\f$
- flag is set: \f$dst(x,y) = src( \rho , \phi )\f$
*/
WARP_INVERSE_MAP = 16
};
uj5u.com熱心網友回復:
是的,正如您提到的,更高的輸入解析度會改善結果,即使您沒有任何速度問題。對您的回應似乎可疑的一點是,據我所知,OpenCV 中只會應用一個插值標志,并且它們的組合沒有任何影響。您可以查看 OpenCV 源代碼,以根據您的輸入檢查真正應用的插值方法。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/374022.html
