python opencv 画米字形状

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

效果图:

代码: 

  1. import cv2
  2. img=cv2.imread('2621.jpg')
  3. if img.shape[1] > 15000:
  4. x_scale = 15000 / img.shape[1]
  5. img = cv2.resize(img, None, fx=x_scale, fy=x_scale, interpolation=cv2.INTER_AREA)
  6. height,width=img.shape[:2]
  7. thickness = 1
  8. lineType = 4
  9. points=[[0,0,width,height]]
  10. points.append([0,0,width//2,height//2])
  11. points.append([width//2,0,width,height//2])
  12. points.append([0,height//2,width//2,height])
  13. points.append([width//2,height//2,width,height])
  14. for point in points:
  15. x1,y1,x2,y2=point
  16. ptStart = (x1, y1)
  17. ptEnd = (x2,y2)
  18. lines=[[(x1, y2),(x2,y1)]]
  19. lines.append([(x1, y1),(x2,y2)])
  20. lines.append([(x1, (y1+ y2)//2),(x2, (y1+ y2)//2)])
  21. lines.append([((x1+x2)//2, y1),((x1+x2)//2,y2)])
  22. for data in lines:
  23. cv2.line(img, data[0], data[1], (0, 0, 255), thickness, lineType)
  24. cv2.imwrite("result.jpg",img)
  25. # cv2.imshow("sadf",img)
  26. # cv2.waitKey()

相关文章