python-3.x - 正确对齐图像
问题描述
嗨,我正在尝试仅从图像中获取手写数据,因为我拍摄了一张空图像和一张填充图像,然后我正在执行 ImageChops.difference 以从中获取数据。现在的问题在于图像的对齐方式,两者在深度方面的对齐方式并不相同,因此结果不正确。
从 PIL 导入 Image、ImageChops
def compare_images(path_one, path_two, diff_save_location):
"""
Compares to images and saves a diff image, if there
is a difference
@param: path_one: The path to the first image
@param: path_two: The path to the second image
"""
image_one = Image.open(path_one).convert('LA')
image_two = Image.open(path_two).convert('LA')
diff = ImageChops.difference(image_one, image_two)
if diff.getbbox():
diff.convert('RGB').save(diff_save_location)
if __name__ == '__main__':
compare_images('images/blank.jpg',
'images/filled.jpg',
'images/diff.jpg')
谁能帮我这个。谢谢。
解决方案
This site may be helpful: https://www.learnopencv.com/image-alignment-feature-based-using-opencv-c-python/ . The main idea is to first detect keypoints use SIFT, SURF or other algorithms in both images; then match the keypoints from the empty image with the keypoints from the handwritten image, to get a homography matrix; then use this matrix to align the two images.
After image alignment, post processing may be needed due to illumination or noise.
推荐阅读
- ios - 聚焦时如何修复 UISearchController 搜索栏调整大小?
- python-3.x - 使用 ax.annotate 时如何适合行尾标签?
- algorithm - 对象到对象/值到值的存储和查找
- angular - NGRX 效果序列相关的 api 调用
- c# - Asp.net 无法将值从选择发送到控制器中的 http 帖子
- kubernetes-helm - 卸载版本时如何保留集群上的资源?
- javascript - “无法读取未定义的属性‘节点’”从我所在州的数组访问数据时出错
- laravel - 找不到类“Mpdf\Mpdf”(Laravel 作业)
- python - 将 lookup_users 方法的结果保存在 json 文件中
- css - WordPress子主题未加载style.css