Hotunan dinki ta amfani Python da OpenCV sun haɗa da haɗa hotuna da yawa don ƙirƙirar fage ko kallon fage mai faɗi. Ana amfani da wannan tsari galibi a cikin daukar hoto don haɗa hotuna masu cin karo da juna da ƙirƙirar fakitin mara nauyi. Anan ga ainihin ƙayyadaddun yadda ake ɗinke hotuna ta amfani da OpenCV:
Shirya Hoto
Loda hotunan da kuke son dinke ta amfani da cv2.imread()
aikin OpenCV.
Maida hotuna zuwa launin toka ta amfani da cv2.cvtColor()
idan ya cancanta.
Gano mahimman fasalulluka a cikin hotuna ta amfani da algorithms gano fasali kamar SIFT, ORB, ko AKAZE.
Daidaita Siffar
Yi amfani da dabarun daidaita fasalin don nemo madaidaitan maki tsakanin hotuna.
OpenCV yana ba da ayyuka kamar cv2.BFMatcher()
ko cv2.FlannBasedMatcher()
don daidaita fasalin.
Ƙimar Homography
Yi lissafin matrix homography ta amfani da madaidaitan maki da aka samu a matakin baya.
Matrix homography yana bayyana canji tsakanin hotuna biyu.
Warping da dinki
Yi amfani da matrix homography don karkatar da ɗayan hotuna don daidaitawa da ɗayan.
cv2.warpPerspective()
Ana iya amfani da aikin don wannan dalili .
Haɗa hoton da ba daidai ba tare da ɗayan hoton don ƙirƙirar panorama ɗin ɗinki.
Haɗuwa(Na zaɓi)
Aiwatar da dabarun haɗa hoto don haɗa hotuna da aka dinka ba tare da matsala ba.
Za a iya amfani da dabaru kamar haɗaɗɗen layi ko haɗaɗɗen bandeji da yawa.
Nuna ko Ajiye
Nuna panorama ɗin da aka dinka ta amfani da cv2.imshow()
ko ajiye shi ta amfani da cv2.imwrite()
.
Anan ga ƙaƙƙarfan misali na lamba wanda ke nuna tsarin ɗinke hoto ta amfani da OpenCV:
import cv2
# Load images
image1 = cv2.imread('image1.jpg')
image2 = cv2.imread('image2.jpg')
# Convert images to grayscale
gray1 = cv2.cvtColor(image1, cv2.COLOR_BGR2GRAY)
gray2 = cv2.cvtColor(image2, cv2.COLOR_BGR2GRAY)
# Detect key features and descriptors
orb = cv2.ORB_create()
keypoints1, descriptors1 = orb.detectAndCompute(gray1, None)
keypoints2, descriptors2 = orb.detectAndCompute(gray2, None)
# Feature matching
matcher = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
matches = matcher.match(descriptors1, descriptors2)
# Apply ratio test to filter good matches
matches = [match for match in matches if match.distance < 0.7 * max(len(matches), 1)]
# Find corresponding points
src_pts = [keypoints1[match.queryIdx].pt for match in matches]
dst_pts = [keypoints2[match.trainIdx].pt for match in matches]
# Calculate homography matrix
homography, _ = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC)
# Warp and stitch images
stitched_image = cv2.warpPerspective(image1, homography,(image1.shape[1] + image2.shape[1], image1.shape[0]))
stitched_image[0:image2.shape[0], 0:image2.shape[1]] = image2
# Display or save the stitched image
cv2.imshow('Stitched Image', stitched_image)
cv2.waitKey(0)
cv2.destroyAllWindows()
Lura cewa wannan misalin sauƙaƙan nuni ne. A aikace, ƙila za ku buƙaci magance batutuwa kamar daidaita hoto, haɗawa, da gyaran murdiya don cimma manyan hotuna masu inganci.