久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

帶虛線或虛線的opencv矩形

opencv rectangle with dotted or dashed lines(帶虛線或虛線的opencv矩形)
本文介紹了帶虛線或虛線的opencv矩形的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我這里有一行代碼使用了opencv的python綁定:

I have a line of code here that uses the python binding for opencv:

cv2.rectangle(img, (box[1], box[0]), (box[3], box[2]), (255,0,0), 4)

這會在厚度為 4 的圖像 img 上繪制一個紅色矩形.

This draws a red rectangle on image img of thickness 4.

但是有沒有辦法可以對矩形的線條進行風格化?沒有太多.只是點綴或虛線,就是這樣.

But is there a way the lines of the rectangles can be stylized? Not too much. Just dotted, or dashed, that's it really.

推薦答案

import cv2
import numpy as np
def drawline(img,pt1,pt2,color,thickness=1,style='dotted',gap=20):
    dist =((pt1[0]-pt2[0])**2+(pt1[1]-pt2[1])**2)**.5
    pts= []
    for i in  np.arange(0,dist,gap):
        r=i/dist
        x=int((pt1[0]*(1-r)+pt2[0]*r)+.5)
        y=int((pt1[1]*(1-r)+pt2[1]*r)+.5)
        p = (x,y)
        pts.append(p)

    if style=='dotted':
        for p in pts:
            cv2.circle(img,p,thickness,color,-1)
    else:
        s=pts[0]
        e=pts[0]
        i=0
        for p in pts:
            s=e
            e=p
            if i%2==1:
                cv2.line(img,s,e,color,thickness)
            i+=1

def drawpoly(img,pts,color,thickness=1,style='dotted',):
    s=pts[0]
    e=pts[0]
    pts.append(pts.pop(0))
    for p in pts:
        s=e
        e=p
        drawline(img,s,e,color,thickness,style)

def drawrect(img,pt1,pt2,color,thickness=1,style='dotted'):
    pts = [pt1,(pt2[0],pt1[1]),pt2,(pt1[0],pt2[1])] 
    drawpoly(img,pts,color,thickness,style)

im = np.zeros((800,800,3),dtype='uint8')
s=(234,222)
e=(500,700)
drawrect(im,s,e,(0,255,255),1,'dotted')

cv2.imshow('im',im)
cv2.waitKey()      

這篇關于帶虛線或虛線的opencv矩形的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 国产一区二区三区在线免费 | 黑人精品| 国产成人综合一区二区三区 | 亚洲欧美日韩久久 | 97精品超碰一区二区三区 | a级免费黄色片 | 欧美精品中文字幕久久二区 | 99福利视频 | 粉嫩一区二区三区国产精品 | 亚洲视频一区二区三区四区 | 国产精品成人在线播放 | 亚州激情| 一区二区三区小视频 | 成人亚洲片 | 国产91亚洲精品一区二区三区 | 北条麻妃99精品青青久久 | 国产精品美女久久久 | 春色av| 看特级黄色片 | 精品在线一区 | 午夜视频免费在线观看 | 欧美白人做受xxxx视频 | 欧美在线a | 久久免费视频观看 | 91久久视频 | 91看片免费| 麻豆毛片 | 国产黑丝av | 国产综合久久 | 视频在线一区二区 | 91一区二区三区在线观看 | 国产精品无 | 久久精品视频网站 | 一级黄色毛片免费 | 国产精品免费一区二区三区 | 欧美激情一区二区三区 | 精品国产区 | 91看片视频 | 精品欧美一区二区精品久久久 | 精品96久久久久久中文字幕无 | 日韩三级免费网站 |