欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

如何使用yolov5輸出檢測(cè)到的目標(biāo)坐標(biāo)信息

 更新時(shí)間:2022年03月28日 09:34:45   作者:一位安分的碼農(nóng)  
YOLOv5是一系列在 COCO 數(shù)據(jù)集上預(yù)訓(xùn)練的對(duì)象檢測(cè)架構(gòu)和模型,下面這篇文章主要給大家介紹了關(guān)于如何使用yolov5輸出檢測(cè)到的目標(biāo)坐標(biāo)信息的相關(guān)資料,需要的朋友可以參考下

找到detect.py,在大概113行,找到plot_one_box

? ? ? ? ? ? ? ? # Write results
? ? ? ? ? ? ? ? for *xyxy, conf, cls in reversed(det):
? ? ? ? ? ? ? ? ? ? if save_txt: ?# Write to file
? ? ? ? ? ? ? ? ? ? ? ? xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() ?# normalized xywh
? ? ? ? ? ? ? ? ? ? ? ? with open(txt_path + '.txt', 'a') as f:
? ? ? ? ? ? ? ? ? ? ? ? ? ? f.write(('%g ' * 5 + '\n') % (cls, *xywh)) ?# label format

? ? ? ? ? ? ? ? ? ? if save_img or view_img: ?# Add bbox to image
? ? ? ? ? ? ? ? ? ? ? ? label = '%s %.2f' % (names[int(cls)], conf)
? ? ? ? ? ? ? ? ? ? ? ? plot_one_box(xyxy, im0, label=label, color=colors[int(cls)], line_thickness=3)

ctr+鼠標(biāo)點(diǎn)擊,進(jìn)入general.py,并自動(dòng)定位到plot_one_box函數(shù),修改函數(shù)為

def plot_one_box(x, img, color=None, label=None, line_thickness=None):
    # Plots one bounding box on image img
    tl = line_thickness or round(0.002 * (img.shape[0] + img.shape[1]) / 2) + 1  # line/font thickness
    color = color or [random.randint(0, 255) for _ in range(3)]
    c1, c2 = (int(x[0]), int(x[1])), (int(x[2]), int(x[3]))
    cv2.rectangle(img, c1, c2, color, thickness=tl, lineType=cv2.LINE_AA)
    print("左上點(diǎn)的坐標(biāo)為:(" + str(c1[0]) + "," + str(c1[1]) + "),右下點(diǎn)的坐標(biāo)為(" + str(c2[0]) + "," + str(c2[1]) + ")")

即可輸出目標(biāo)坐標(biāo)信息了

附:python yolov5檢測(cè)模型返回坐標(biāo)的方法實(shí)例代碼

python yolov5檢測(cè)模型返回坐標(biāo)的方法 直接搜索以下代碼替換下 

 if save_img or view_img:  # Add bbox to image
                        label = f'{names[int(cls)]} {conf:.2f}'
                        c1, c2 = (int(xyxy[0]), int(xyxy[1])), (int(xyxy[2]), int(xyxy[3]))
                        print("左上點(diǎn)的坐標(biāo)為:(" + str(c1[0]) + "," + str(c1[1]) + "),右下點(diǎn)的坐標(biāo)為(" + str(c2[0]) + "," + str(c2[1]) + ")")
                        return [c1,c2]
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--weights', nargs='+', type=str, default='yolov5s.pt', help='model.pt path(s)')
parser.add_argument('--source', type=str, default='data/images', help='source') # file/folder, 0 for webcam
parser.add_argument('--img-size', type=int, default=640, help='inference size (pixels)')
parser.add_argument('--conf-thres', type=float, default=0.25, help='object confidence threshold')
parser.add_argument('--iou-thres', type=float, default=0.45, help='IOU threshold for NMS')
parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
parser.add_argument('--view-img', action='store_true', help='display results')
parser.add_argument('--save-txt', action='store_true', help='save results to *.txt')
parser.add_argument('--save-conf', action='store_true', help='save confidences in --save-txt labels')
parser.add_argument('--nosave', action='store_true', help='do not save images/videos')
parser.add_argument('--classes', nargs='+', type=int, help='filter by class: --class 0, or --class 0 2 3')
parser.add_argument('--agnostic-nms', action='store_true', help='class-agnostic NMS')
parser.add_argument('--augment', action='store_true', help='augmented inference')
parser.add_argument('--update', action='store_true', help='update all models')
parser.add_argument('--project', default='runs/detect', help='save results to project/name')
parser.add_argument('--name', default='exp', help='save results to project/name')
parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment')
opt = parser.parse_args()

check_requirements(exclude=('pycocotools', 'thop'))

opt.source='data/images/1/'
result=detect()
print('最終檢測(cè)結(jié)果:',result);

總結(jié)

到此這篇關(guān)于如何使用yolov5輸出檢測(cè)到的目標(biāo)坐標(biāo)信息的文章就介紹到這了,更多相關(guān)yolov5輸出目標(biāo)坐標(biāo)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • python三引號(hào)輸出方法

    python三引號(hào)輸出方法

    在本文里我們給大家分析那個(gè)了關(guān)于python三引號(hào)輸出方法以及相關(guān)知識(shí)點(diǎn),需要的朋友們學(xué)習(xí)下。
    2019-02-02
  • Python Matplotlib繪圖基礎(chǔ)知識(shí)代碼解析

    Python Matplotlib繪圖基礎(chǔ)知識(shí)代碼解析

    這篇文章主要介紹了Python Matplotlib繪圖基礎(chǔ)知識(shí)代碼解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-08-08
  • Python實(shí)現(xiàn)把json格式轉(zhuǎn)換成文本或sql文件

    Python實(shí)現(xiàn)把json格式轉(zhuǎn)換成文本或sql文件

    這篇文章主要介紹了Python實(shí)現(xiàn)把json格式轉(zhuǎn)換成文本或sql文件,本文直接給出代碼實(shí)例,需要的朋友可以參考下
    2015-07-07
  • Python面向?qū)ο缶幊讨?lèi)的封裝

    Python面向?qū)ο缶幊讨?lèi)的封裝

    這篇文章主要介紹了Python面向?qū)ο缶幊讨?lèi)的封裝封裝指屬性和方法的抽象,屬性的抽象又指對(duì)類(lèi)的屬性進(jìn)行定義、隔離和保護(hù),下面來(lái)看看文章的具體內(nèi)容吧,需要的朋友可以參考一下,希望對(duì)你有所幫助
    2021-11-11
  • Python爬取豆瓣數(shù)據(jù)實(shí)現(xiàn)過(guò)程解析

    Python爬取豆瓣數(shù)據(jù)實(shí)現(xiàn)過(guò)程解析

    這篇文章主要介紹了Python爬取豆瓣數(shù)據(jù)實(shí)現(xiàn)過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-10-10
  • Python中的map()函數(shù)和reduce()函數(shù)的用法

    Python中的map()函數(shù)和reduce()函數(shù)的用法

    這篇文章主要介紹了Python中的map()函數(shù)和reduce()函數(shù)的用法,代碼基于Python2.x版本,需要的朋友可以參考下
    2015-04-04
  • 使用scrapy實(shí)現(xiàn)增量式爬取方式

    使用scrapy實(shí)現(xiàn)增量式爬取方式

    這篇文章主要介紹了使用scrapy實(shí)現(xiàn)增量式爬取方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-06-06
  • Django基于Models定制Admin后臺(tái)實(shí)現(xiàn)過(guò)程解析

    Django基于Models定制Admin后臺(tái)實(shí)現(xiàn)過(guò)程解析

    這篇文章主要介紹了Django基于Models定制Admin后臺(tái)實(shí)現(xiàn)過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-11-11
  • 使用Pycharm為項(xiàng)目創(chuàng)建一個(gè)虛擬環(huán)境完整圖文教程

    使用Pycharm為項(xiàng)目創(chuàng)建一個(gè)虛擬環(huán)境完整圖文教程

    這篇文章主要給大家介紹了關(guān)于使用Pycharm為項(xiàng)目創(chuàng)建一個(gè)虛擬環(huán)境的相關(guān)資料,我們?cè)谑褂胮ycharm做項(xiàng)目時(shí),最好給每一個(gè)工程都創(chuàng)建一個(gè)虛擬環(huán)境,將對(duì)應(yīng)的安裝包放在該虛擬環(huán)境中,避免項(xiàng)目與項(xiàng)目之間產(chǎn)生關(guān)系或沖突,便于管理,需要的朋友可以參考下
    2023-09-09
  • python for循環(huán)輸入一個(gè)矩陣的實(shí)例

    python for循環(huán)輸入一個(gè)矩陣的實(shí)例

    今天小編就為大家分享一篇python for循環(huán)輸入一個(gè)矩陣的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-11-11

最新評(píng)論