python opencv 画米字形状

x33g5p2x  于2022-03-11 转载在 Python  
字(0.8k)|赞(0)|评价(0)|浏览(138)

效果图:

代码: 

import cv2

img=cv2.imread('2621.jpg')

if img.shape[1] > 15000:
    x_scale = 15000 / img.shape[1]

    img = cv2.resize(img, None, fx=x_scale, fy=x_scale, interpolation=cv2.INTER_AREA)

height,width=img.shape[:2]
thickness = 1
lineType = 4

points=[[0,0,width,height]]
points.append([0,0,width//2,height//2])
points.append([width//2,0,width,height//2])
points.append([0,height//2,width//2,height])
points.append([width//2,height//2,width,height])

for point in points:
    x1,y1,x2,y2=point
    ptStart = (x1, y1)
    ptEnd = (x2,y2)

    lines=[[(x1, y2),(x2,y1)]]

    lines.append([(x1, y1),(x2,y2)])

    lines.append([(x1, (y1+ y2)//2),(x2, (y1+ y2)//2)])
    lines.append([((x1+x2)//2, y1),((x1+x2)//2,y2)])

    for data in lines:
        cv2.line(img, data[0], data[1], (0, 0, 255), thickness, lineType)

cv2.imwrite("result.jpg",img)
# cv2.imshow("sadf",img)
# cv2.waitKey()

相关文章