2012-11-26 25 views
10

मैंने दो तस्वीरें (ए और बी) से थोड़ा अन्य, जहां (उदाहरण के लिए, इन चित्रों :)OpenCV में चित्रों को बदलने के लिए होमोग्राफी का उपयोग कैसे करें?

ORIGINAL LENA DISTORTED LENA


उन दोनों के बीच अनुवाद, रोटेशन और पैमाने मतभेद हैं से एक विकृत

Ssoooooooo मैं क्या जरूरत पिक बी में परिवर्तन का एक प्रकार लागू करने के लिए तो यह विरूपण/अनुवाद/रोटेशन एक ही आकार, ओरिएंटेशन के साथ और कोई अनुवाद के साथ दोनों चित्रों बनाने के लिए मौजूद है कि क्षतिपूर्ति है

मैं पहले से ही है बिंदुओं को निकाला और Homography पाया, जैसा कि दिखाया गया है। लेकिन मुझे नहीं पता कि Mat img_B को बदलने के लिए होमोग्राफी का उपयोग कैसे करें, इसलिए यह Mat img_A जैसा दिखता है। कोई उपाय?

//-- 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); 

चीयर्स,

उत्तर

5

आप warpPerspective समारोह चाहते हैं। यह प्रक्रिया this ट्यूटोरियल (एफ़िन ट्रांसफॉर्म और वॉरप्स के लिए) में प्रस्तुत की गई है,

7

आपको इस समस्या के लिए होमोग्राफी की आवश्यकता नहीं है। आप इसके बजाए एक एफ़िन ट्रांसफॉर्म की गणना कर सकते हैं। हालांकि, यदि आप अन्य प्रयोजनों के लिए होमोग्राफी का उपयोग करना चाहते हैं, तो आप नीचे दिए गए कोड को देख सकते हैं। इसे this से homography पर बहुत विस्तृत लेख से कॉपी किया गया था।

सी ++ उदाहरण

// 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); 

अजगर उदाहरण

''' 
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) 

 संबंधित मुद्दे

  • कोई संबंधित समस्या नहीं^_^