zoukankan      html  css  js  c++  java
  • python3 使用opencv 画基本图形

    在Python3 环境下安装opencv-python 后练习画基本图形:

    import numpy as np
    import cv2
    
    # BGR format
    GREEN     = (0, 255, 0)
    RED     = (0, 0, 255)
    BLUE     = (255, 0, 0)
    WHITE    = (255,255,255)
    
    canvas = np.zeros((300,300,3), dtype = "uint8")
    # 画线,框,⚪
    cv2.line(canvas,(0,0), (300,300), GREEN, 2)
    # cv2.imshow("Canvas", canvas)
    cv2.rectangle(canvas,(10,10), (60,60),GREEN, 1)
    cv2.rectangle(canvas,(300,0), (0,300),RED,5)
    cv2.rectangle(canvas, (200,55), (55,200), BLUE, -1)
    (cx, cy) = (canvas.shape[1]/2, canvas.shape[0]/2)
    for r in range(0, 200, 25):
        print(cx,cy,r)
        cv2.circle(canvas, (int(cx), int(cy)), r, WHITE)
    
    cv2.imshow('Canvas', canvas)
    cv2.waitKey(0)
    
    canvas = np.zeros((300,300,3), dtype = "uint8")
    # 随机画⚪
    for i in range(0, 25):
        r = np.random.randint(5, 200)
        color = np.random.randint(0, high = 256, size = (3,)).tolist()
        pt = np.random.randint(0, high = 300, size = (2,))
        print(r)
        print("*" * 25)
        print(color)
        print("*" * 25)
        print(pt)
        cv2.circle(canvas, tuple(pt), r, color, -1)
    
    cv2.imshow("Canvas", canvas)
    cv2.waitKey(0)

    运行后可看到以下效果.

  • 相关阅读:
    std::auto_ptr
    make_pair
    _stdcall与_cdecl(了解)
    函数名与函数指针(了解)
    空指针与野指针
    std::bind(二)
    C++ map 映照容器
    sql find duplicate
    数量
    sort sign numeric
  • 原文地址:https://www.cnblogs.com/gxgl314/p/9262756.html
Copyright © 2011-2022 走看看