我正在嘗試使用 opencv 行函式復制示例影像上的內容。我已經能夠在目標影像上畫線,但線斷了,
我想對齊虛線,以便它們可以顯示為示例影像,請問我該如何實作。
下面是帶有虛線的輸出影像。
示例圖片
輸出影像
我的示例代碼。
results = hr['matchedPoints1'].values.tolist()
results2 = hr2['matchedPoints2'].values.tolist()
for i in zip(results, results2):
color = tuple(np.random.randint(0,255,3).tolist())
(x1, y1), (x2, y2) = i
print( (x1, y1), (x2, y2))
cv2.line(img1, (x1,y1), (x2,y2),(255,255,255), 2)
img1 = cv2.cvtColor(img1,cv2.COLOR_BGR2RGB)
plt.subplot(121),plt.imshow(img1)
plt.show()
從下面的兩個匹配點中提取的線
(89, 368) (108, 343)
(39, 384) (57, 354)
(109, 532) (54, 492)
(685, 320) (711, 348)
(625, 292) (647, 308)
(625, 306) (646, 331)
(176, 466) (139, 442)
(156, 350) (118, 330)
(269, 318) (232, 308)
(269, 301) (229, 293)
(632, 209) (659, 225)
(587, 138) (617, 147)
(578, 80) (609, 86)
(571, 128) (601, 135)
(388, 155) (390, 155)
(370, 88) (371, 90)
(364, 159) (366, 158)
(211, 189) (199, 181)
(193, 240) (198, 234)
(194, 264) (199, 253)
(103, 292) (106, 271)
(135, 331) (112, 308)
目標影像
下面是我的 cameraMatrices 和 MatchedPoints。
匹配點1
89.6214953271028,368.64953271028
39.3785046728971,384.200934579439
109.957943925234,532.53738317757
685.359813084112,320.799065420561
625.546728971963,292.088785046729
625.546728971963,306.443925233645
176.948598130841,466.742990654206
156.61214953271,350.705607476636
269.060747663551,318.406542056075
269.060747663551,301.658878504673
632.724299065421,209.546728971963
587.266355140187,138.967289719626
578.892523364486,80.3504672897196
571.714953271028,128.200934579439
388.686915887851,155.714953271028
370.742990654206,88.7242990654206
364.761682242991,159.303738317757
211.640186915888,189.210280373832
193.696261682243,240.64953271028
194.892523364486,264.57476635514
103.976635514019,292.088785046729
135.079439252336,331.565420560748
匹配點2
108.593312597201,343.442457231726
57.2340590979786,354.192068429238
54.8452566096425,492.742612752722
711.765940902022,348.220062208398
647.268273716952,308.804821150855
646.073872472784,331.498444790047
139.647744945568,442.577760497667
118.148522550545,330.304043545879
232.811041990669,308.804821150855
229.227838258165,293.277604976672
659.212286158632,225.196734059098
617.408242612753,147.56065318818
609.047433903577,86.6461897356141
601.88102643857,135.616640746501
390.47200622084,155.921461897356
371.361586314153,90.229393468118
366.583981337481,158.310264385692
199.367807153966,181.003888024883
198.173405909798,234.751944012442
199.367807153966,253.862363919129
106.204510108865,271.778382581648
112.176516329705,308.804821150855
uj5u.com熱心網友回復:
每組點對于相應的影像都是唯一的。
我已經展示了如何使用以下方法獲取第一張影像的可視化MatchedPoints1:
MatchedPoints1 = [(89.6214953271028,368.64953271028),
(39.3785046728971,384.200934579439),
(109.957943925234,532.53738317757),
(685.359813084112,320.799065420561),
(625.546728971963,292.088785046729),
(625.546728971963,306.443925233645),
(176.948598130841,466.742990654206),
(156.61214953271,350.705607476636),
(269.060747663551,318.406542056075),
(269.060747663551,301.658878504673),
(632.724299065421,209.546728971963),
(587.266355140187,138.967289719626),
(578.892523364486,80.3504672897196),
(571.714953271028,128.200934579439),
(388.686915887851,155.714953271028),
(370.742990654206,88.7242990654206),
(364.761682242991,159.303738317757),
(211.640186915888,189.210280373832),
(193.696261682243,240.64953271028),
(194.892523364486,264.57476635514),
(103.976635514019,292.088785046729),
(135.079439252336,331.565420560748)]
img = cv2.imread('house.png')
img2 = img.copy()
for e, i in enumerate(MatchedPoints1):
color = tuple(np.random.randint(0,255,3).tolist())
if (e < (len(MatchedPoints1) - 1)):
img2 = cv2.line(img2, (int(i[0]), int(i[1])), (int(MatchedPoints1[e 1][0]), int(MatchedPoints1[e 1][1])), color, 2)
img2 = cv2.circle(img2, (int(i[0]), int(i[1])), 5, color, -1)
結果:

第二張圖片也可以使用
MatchedPoints2.
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/483303.html
