cv2 识别图片缺口滑动距离

import cv2 as cv
import numpy as np
print(cv.version)

def takeSecond(elem):
return elem[1]

##读取滑块图
block = cv.imread(“picture/block.png”, -1)
backimg = cv.imread(“picture/bg.jpg”)
cv.imshow(“block origin”, block)
##灰度化
gray_backimg = cv.cvtColor(backimg, cv.COLOR_RGB2GRAY)
blockWidth, blockHeight = block.shape[1], block.shape[0]

##识别滑块图前景
###由于滑块图为带透明的png,可根据透明通道来判断前景位置
##识别物体框,生成blockmask
left = blockWidth
right = 0
top = blockHeight
bottom = 0
for i in range(0, blockHeight):
for j in range(0, blockWidth):
if block[i, j, 3] > 0:
if j <= left:
left = j
if j >= right:
right = j
if i <= top:
top = i
if i >= bottom:
bottom = i
blockBox = block[top:bottom, left:right]
blockBox_width, blockBox_

你可能感兴趣的:(cv2 识别图片缺口滑动距离)