Python OpenCV 简单图像比较
2023-09-27 14:27:48 时间
项目需要做两张图像比较的差,感觉Python用起来很方便,手头正好有OpenCV。红绿代表插值正负,为了更好的可视化,差值均放大10倍显示。
-
import cv2
-
-
-
def clmap(v, k, upBound): #mul and clamp
-
val = v * k
-
if val > upBound:
-
return upBound
-
else:
-
return val
-
-
-
inImage_1 = 'B_Tri.bmp' #
-
inImage_2 = 'B_RT.bmp' #
-
-
dif_img = 'dif_' + inImage_1
-
-
img_1 = cv2.imread(inImage_1) # read as color image
-
img_2 = cv2.imread(inImage_2)
-
-
dif = img_1.copy()
-
show_dif = dif.copy() # dif image for show only
-
-
width = img_1.shape[ 0] #get width
-
height = img_1.shape[ 1] #get height
-
-
for i in range(width):
-
for j in range(height):
-
#dif[i, j] = [128,0,0] # b g r
-
#print img_1[i,j]-img_2[i,j]
-
-
diff = int(img_1[i,j][ 0])-int(img_2[i,j][ 0])
-
-
if diff < 0:
-
show_dif[i,j] = [ 0,clmap(abs(diff), 10, 255), 0]
-
-
elif diff > 0:
-
show_dif[i, j]= [ 0, 0, clmap(abs(diff), 10, 255)]
-
else:
-
show_dif[i,j] = [ 0]
-
-
dif[i,j] = [abs(diff)] * 3
-
-
print dif_img
-
print 'different data:'
-
print 'max : ', dif.max()
-
print 'min : ', dif.min()
-
print 'mean : ', dif.mean()
-
-
-
cv2.imwrite(dif_img, show_dif)
-
-
-
cv2.imshow( '_dif',show_dif)
-
cv2.waitKey( 0)
-
cv2.destroyAllWindows()
image1
image2
dif
相关文章
- python学习系列-3-求知讲堂python
- 【Python】ValueError: unsupported pickle protocol: 5解决方案/同一个项目 python环境尽量保持一致
- Python输出带颜色字体
- 30岁一无所长,转行做什么?我为什么会选择python?
- 截止2022-06-05,可以用Python的Pip命令安装OpenCV的哪些版本?
- 使用OpenCV-Python的函数minMaxLoc()应该注意的两点
- 《Python 3程序开发指南(第2版•修订版)》——1.4 总结
- python学习之安装python-opencv库(测试有效)
- 基于Python(Pyecharts)绘制个人足迹地图【100010383】
- Python数据可视化 Pyecharts 制作 Radar 雷达图
- Opencv教程(Python)
- Python代码库OpenCV之08图像过滤blur(含代码)
- Python代码库OpenCV之12提取碑文文字并分割
- 基于Python实现的个性化电影推荐系统 | 爬虫 | Python
- 使用opencv-python和dlib实现的简单换脸程序
- python安装opencv
- Python Opencv 之 使用 teesseract 进行简单的文字识别(包括中文)
- Python删除列表元素
- 【ESP32Cam项目1】:ESP32Cam人脸检测(ArduinoESP32底层、Python版opencv)
- 【图像处理】——Python实现几何变换(自定义+opencv库)
- 【Python】pycharm opencv没有智能提示开启
- Python opencv-python 简单测试
- python量化交易学习笔记(三)——第一个策略回测程序Demo6
- opencv python数据增强