python-3.x - cv2.findTransformECC 如何忽略小颗粒
问题描述
我尝试根据零件的轮廓对齐测量图像。不幸的是,周围的粒子通常被认为过于对齐,我得到了错误的结果。
这是我使用的基本 openCV 代码。也许我必须以某种方式过滤粒子,然后在原始图像上使用包裹矩阵。
im1 = cv2.imread(im1Conv)
im2 = cv2.imread(im2Conv)
# Convert images to grayscale
im1 = cv2.cvtColor(im1,cv2.COLOR_BGR2GRAY)
im2 = cv2.cvtColor(im2,cv2.COLOR_BGR2GRAY)
# percent of original size
width = int(im1.shape[1] * scale_percent / 100)
height = int(im1.shape[0] * scale_percent / 100)
dim1 = (width, height)
# percent of original size
width = int(im2.shape[1] * scale_percent / 100)
height = int(im2.shape[0] * scale_percent / 100)
dim2 = (width, height)
# resize image
im1 = cv2.resize(im1, dim1, interpolation = cv2.INTER_AREA)
im2 = cv2.resize(im2, dim2, interpolation = cv2.INTER_AREA)
# Find size of image1
sz = im1.shape
# Define the motion model
if convMode != "down":
warp_mode = cv2.MOTION_EUCLIDEAN
else:
warp_mode = cv2.MOTION_HOMOGRAPHY
# Define 2x3 or 3x3 matrices and initialize the matrix to identity
if warp_mode == cv2.MOTION_HOMOGRAPHY:
warp_matrix = np.eye(3, 3, dtype=np.float32)
else:
warp_matrix = np.eye(2, 3, dtype=np.float32)
# Specify the number of iterations.
number_of_iterations = int(iteFromUi);
# Specify the threshold of the increment
# in the correlation coefficient between two iterations
termination_eps = float(koreFromUi);
# Define termination criteria
criteria = (cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, number_of_iterations, termination_eps)
# Run the ECC algorithm. The results are stored in warp_matrix.
(cc, warp_matrix) = cv2.findTransformECC (im1,im2,warp_matrix, warp_mode, criteria)
if warp_mode == cv2.MOTION_HOMOGRAPHY :
# Use warpPerspective for Homography
im2_aligned = cv2.warpPerspective (im2, warp_matrix, (sz[1],sz[0]), flags=cv2.INTER_LINEAR + cv2.WARP_INVERSE_MAP)
else :
# Use warpAffine for Translation, Euclidean and Affine
im2_aligned = cv2.warpAffine(im2, warp_matrix, (sz[1],sz[0]), flags=cv2.INTER_LINEAR + cv2.WARP_INVERSE_MAP);
有谁知道我该如何解决这个问题?
不幸的是,我无法提供要分析的图像。它们看起来像这样:
与特征匹配 (Sift) 的结果相同:
解决方案
推荐阅读
- ruby-on-rails - 红宝石哈希中的条件设置值
- javascript - 在 ReactJS 中将单个对象转换为对象数组
- python - 激活 Anaconda 环境时出现“无效选择”
- python - 列表中元素的问题
- javascript - 日期选择器字段中的表单验证无法正常工作
- tensorflow - 使用 TFrecords 时如何设置 epoch?
- python - 运行创建许多文件的程序时偶尔返回“权限错误”
- sql - 如何解决此错误“除以零”
- angular - 使用 Angular 6、angular-oauth2-oidc 和 IdentityServer 3 返回 URL
- visual-studio-2017 - SSAS 表格 - 模型中的数据,但网格为空白