2012-11-26 17 views
10

Ben ettik iki resim (A ve B) hafifçe (örneğin, bu resimleri :)OpenCV'deki resimleri dönüştürmek için Homography'yi nasıl kullanırsınız?

ORIGINAL LENA DISTORTED LENA


aralarında çevirme, döndürme ve ölçek farklılıkları olduğu yerde, biri diğerinden bozuk aynı boyutta, oryantasyon ile ve hiçbir çeviri ile hem resim yapmak için var distorsiyon/çeviri/dönüşünü dengeler öylesine ihtiyacım olanı

Ssoooooooo pic B'de dönüşümün bir tür uygulamaktır

ben zaten noktaları ayıkladı ve gösterildiği gibi Homografi bulundu. Ama 'u dönüştürmek için Homografi'yi nasıl kullanacağımı bilmiyorum, böylece Mat img_A gibi görünüyor. Herhangi bir fikir?

//-- Localize the object from img_1 in img_2 
std::vector<Point2f> obj; 
std::vector<Point2f> scene; 

for (unsigned int i = 0; i < good_matches.size(); i++) { 
    //-- Get the keypoints from the good matches 
    obj.push_back(keypoints_object[good_matches[i].queryIdx].pt); 
    scene.push_back(keypoints_scene[good_matches[i].trainIdx].pt); 
} 

Mat H = findHomography(obj, scene, CV_RANSAC); 

Alkış,

cevap

5

Sen warpPerspective fonksiyonunu istiyorum. İşlem, this dersinde (afin dönüşümü ve eğrileri için) verilene benzerdir.

7

Bu sorun için homografi gerekmez. Bunun yerine bir afine dönüşümü hesaplayabilirsiniz. Ancak, homografiyi başka amaçlarla kullanmak istiyorsanız, aşağıdaki kodu kontrol edebilirsiniz. this numaralı telefondan homography numaralı telefondan çok detaylı bir makaleye kopyalanmıştır.

C++ Örnek

// pts_src and pts_dst are vectors of points in source 
// and destination images. They are of type vector<Point2f>. 
// We need at least 4 corresponding points. 

Mat h = findHomography(pts_src, pts_dst); 

// The calculated homography can be used to warp 
// the source image to destination. im_src and im_dst are 
// of type Mat. Size is the size (width,height) of im_dst. 

warpPerspective(im_src, im_dst, h, size); 

Python Örnek

''' 
pts_src and pts_dst are numpy arrays of points 
in source and destination images. We need at least 
4 corresponding points. 
''' 
h, status = cv2.findHomography(pts_src, pts_dst) 

''' 
The calculated homography can be used to warp 
the source image to destination. Size is the 
size (width,height) of im_dst 
''' 

im_dst = cv2.warpPerspective(im_src, h, size) 
İlgili konular