python如何利用中心坐標(biāo)繪制矩形
python利用中心坐標(biāo)繪制矩形
python利用matplotlib庫(kù)根據(jù)中心坐標(biāo)與方位角繪制矩形
import matplotlib.pyplot as plt import math def convert_center_to_leftdown(x_cord, y_cord, angle, width, height): xp = x_cord-(math.sqrt(width**2+height**2)/2)*math.cos(math.atan2(height, width)+angle/180*math.pi) yp = y_cord-(math.sqrt(width**2+height**2)/2)*math.sin(math.atan2(height, width)+angle/180*math.pi) return xp, yp fig1 = plt.figure() # 確保正方形在屏幕上顯示一致,固定figure的長(zhǎng)寬相等 axes1 = fig1.add_subplot(1, 1, 1) # 輸入矩形中心坐標(biāo),矩形方位角(逆時(shí)針為正)以及矩形的寬與高即可繪制矩形 x = 0.5 y = 0.5 phi = -30 w = 0.2 h = 0.1 xp, yp = convert_center_to_leftdown(x, y, phi, w, h) square = plt.Rectangle(xy=(xp, yp), width=w, height=h, alpha=0.8, angle=phi) axes1.add_patch(square) # 把圖形加載到繪制區(qū)域 axes1.axis('equal') axes1.grid() plt.show()
opencv-python繪制矩形框
函數(shù)
cv2.rectangle(img, pt1, pt2, color[, thickness[, lineType[, shift]]])?
img
:要畫(huà)的圓所在的矩形或圖像pt1
:矩形左上角的點(diǎn)pt2
:矩形右下角的點(diǎn)color
:線(xiàn)條顏色,如 (0, 0, 255) 紅色,BGRthickness
:線(xiàn)條寬度
lineType:
- 8 (or omitted) : 8-connected line
- 4:4-connected line
- CV_AA - antialiased line
shift
:坐標(biāo)點(diǎn)小數(shù)點(diǎn)位數(shù)
import numpy as np import cv2 as cv img = np.zeros((320, 320, 3), np.uint8) #生成一個(gè)空灰度圖像 print img.shape # 輸出:(320, 320, 3) # 矩形左上角和右上角的坐標(biāo),繪制一個(gè)綠色矩形 ptLeftTop = (60, 60) ptRightBottom = (260, 260) point_color = (0, 255, 0) # BGR thickness = 1? lineType = 4 cv.rectangle(img, ptLeftTop, ptRightBottom, point_color, thickness, lineType) # 繪制一個(gè)紅色矩形 ptLeftTop = (120, 100) ptRightBottom = (200, 150) point_color = (0, 0, 255) # BGR thickness = 1 lineType = 8 cv.rectangle(img, ptLeftTop, ptRightBottom, point_color, thickness, lineType) cv.namedWindow("AlanWang") cv.imshow('AlanWang', img) cv.waitKey (10000) # 顯示 10000 ms 即 10s 后消失 cv.destroyAllWindows()
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Python實(shí)現(xiàn)對(duì)圖像加噪(高斯噪聲 椒鹽噪聲)
這篇文章主要介紹了展示通過(guò)Python給圖像疊加不同等級(jí)的椒鹽噪聲和高斯噪聲的代碼,相應(yīng)的疊加噪聲的已編為對(duì)應(yīng)的類(lèi),可實(shí)例化使用。感興趣的同學(xué)可以看看2021-11-11Python爬蟲(chóng)采集Tripadvisor數(shù)據(jù)案例實(shí)現(xiàn)
這篇文章主要為大家介紹了Python爬蟲(chóng)采集Tripadvisor數(shù)據(jù)案例實(shí)現(xiàn),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-06-06教你用python提取txt文件中的特定信息并寫(xiě)入Excel
這篇文章主要給大家介紹了如何利用python提取txt文件中的特定信息并寫(xiě)入Excel的相關(guān)資料,Python是一個(gè)強(qiáng)大的語(yǔ)言,解決這點(diǎn)問(wèn)題非常簡(jiǎn)單,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2021-11-11Python 3.8中實(shí)現(xiàn)functools.cached_property功能
這篇文章主要介紹了Python 3.8中實(shí)現(xiàn)functools.cached_property功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-05-05python實(shí)現(xiàn)自動(dòng)更換ip的方法
這篇文章主要介紹了python實(shí)現(xiàn)自動(dòng)更換ip的方法,涉及Python針對(duì)本機(jī)網(wǎng)絡(luò)配置的相關(guān)操作技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-05-05PyQt子線(xiàn)程處理業(yè)務(wù)事件的問(wèn)題解決
在PyQt中,主線(xiàn)程通常是指GUI主循環(huán)所在的線(xiàn)程,而子線(xiàn)程則是執(zhí)行實(shí)際工作的線(xiàn)程,本文主要介紹了PyQt子線(xiàn)程處理業(yè)務(wù)事件的問(wèn)題解決,具有一定的參考價(jià)值,感興趣的可以了解一下2024-02-02