根据layout信息扣取panel图片

import pandas as pd
import cv2

def convert_to_top_left_origin(x, y, width, height):
    # 图像中心点的x和y坐标
    center_x = width // 2
    center_y = height // 2

    if x > 0:
        new_x = x + center_x
        if y > 0:
            new_y = center_y - y
        else:
            new_y = center_y + abs(y)
    else:
        new_x = center_x - abs(x)
        if y > 0:
            new_y = center_y - y
        else:
            new_y = center_y + abs(y)
    return new_x,new_y

img = cv2.imread(r'C:\autoMac\imgs1\Z66743KP1926_20240425_103334_11A600_.jpg',0)
_,bimg = cv2.threshold(img,10,255,cv2.THRESH_BINARY)
contours, _ = cv2.findContours(bimg, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
for contour in contours:
    x, y, w, h = cv2.boundingRect(contour)
    glass = img[y:y+h, x:x+w]
H, W = glass.shape
center_x = W//2
center_y = H//2
acc_x = W / 1850
acc_y = H / 1500

glass = cv2.cvtColor(glass,cv2.COLOR_GRAY2BGR)
datas = pd.read_excel(r'E:\412\MAC\670B110(HD080).xlsx')
left_top = datas['Panel左上角-a']
right_bottom = datas['Panel右下角-d']
for i in range(1,len(left_top)):
    left_top_x = datas.iloc[i,3]
    left_top_y = datas.iloc[i,4]
    right_bottom_x = datas.iloc[i,9]
    right_bottom_y = datas.iloc[i, 10]

    x1 = int(left_top_x/1000 * acc_x)
    y1 = int(left_top_y/1000 * acc_y)
    x2 = int(right_bottom_x/1000 * acc_x)
    y2 = int(right_bottom_y/1000 * acc_y)

    x1_, y1_ = convert_to_top_left_origin(x1, y1, W, H)
    x2_, y2_ = convert_to_top_left_origin(x2, y2, W, H)
    if left_top_y == 41006:
        y1_ += 70
        y2_ += 70
    cv2.rectangle(glass, (x1_, y1_), (x2_, y2_), (0, 0, 255), 20)

cv2.namedWindow('0', 0)
cv2.imshow('0', glass)
cv2.waitKey(0)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值