我问过一个可能太复杂的问题。所以在这里,我有了一个新的简单一点。
我有两个图像:
我要做的是将第二个图像居中放置在第一个图像的中央,如下所示。
到目前为止,我所取得的成就是这些图像的核心。
该值是两点XY的列表。
我如何匹配这些点以得到上面想要的结果?
import cv2
import numpy as np
import os
img1 = cv2.imread(os.path.expanduser('~\\Desktop\\c1.png'))
# ---Read image and obtain threshold---
img0 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
ret, thresh = cv2.threshold(img0, 120, 255, 1)
# ---Obtain contours---
image, contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cnts = contours
center = []
for c in cnts:
M = cv2.moments(c)
cX = int(M["m10"] / M["m00"])
cY = int(M["m01"] / M["m00"])
print(cX, cY)
center.append(cX)
center.append(cY)
print(center)
Run Code Online (Sandbox Code Playgroud)
谢谢