库 安装 Pillow pip install Pillow 
 
 
 ImagePIL (Python Imaging Library)get_gapimage1image2get_gap*函数中,定义了一个变量 leftimage1image2is_pixel_equalis_pixel_equalimage1image2(x, y)is_pixel_equal* 函数中,通过 image1.load()[x, y]image2.load()[x, y]*获取两个像素的颜色值。thresholdTrue*,表示两个像素相似;否则返回 Falseimg_cvImage.open'temp_img1.png''temp_img2.png'img1_img2_get_gap* 函数,传入 img1_img2_printimg_cv  
图片用到的测量工具是 Snipaste,之前有介绍过:点我   
 
 
'''
@Time    :2023/8/2 15:06
@作者    :庄志权
@联系    :18721945973
''' 
from  PIL import  Image
def  get_gap ( image1,  image2) : 
    left =  0 
    for  i in  range ( left,  image1. size[ 0 ] ) : 
        for  j in  range ( image1. size[ 1 ] ) : 
            if  not  is_pixel_equal( image1,  image2,  i,  j) : 
                left =  i
                return  left
    return  left
def  is_pixel_equal ( image1,  image2,  x,  y) : 
    pixel1 =  image1. load( ) [ x,  y] 
    pixel2 =  image2. load( ) [ x,  y] 
    threshold =  60 
    if  abs ( pixel1[ 0 ]  -  pixel2[ 0 ] )  <  threshold and  abs ( pixel1[ 1 ]  -  pixel2[ 1 ] )  <  threshold and  abs ( 
            pixel1[ 2 ]  -  pixel2[ 2 ] )  <  threshold: 
        return  True 
    else : 
        return  False 
def  img_cv ( ) : 
    img1_ =  Image. open ( 'temp_img1.png' ) 
    img2_ =  Image. open ( 'temp_img2.png' ) 
    x_pos =  get_gap( img1_,  img2_) 
    return  x_pos
print ( img_cv( ) )