我之前问了一个问题,可能太复杂了。现在我有一个新的问题,稍微简单一些。
我有两张图片:
我想把第二张图片居中放到第一张图片中间,就像下面这样。
我目前实现的是这些图片的中心对齐。
这个值是一个包含两个点(X-Y)的列表。
如何匹配这些点以获得上述所需的结果?
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)
谢谢