91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

基于opencv窗口的多邊型標注工具。輸入bmp,jpg,jpeg等格式圖片,鼠標點擊生成多邊型區域,空格保存json文本文件。適用于多邊型標注,或生成mask圖。

資源截圖

代碼片段和文件信息

#?coding=utf-8
import?numpy?as?np
import?cv2
import?glob
import?os
import?json


class?Draw(object):
????def?__init__(self?img?save_path?d=2?draw=False):
????????self.img?=?img.copy()
????????self.img_copy?=?img.copy()
????????self.img_add?=?img.copy()
????????self.draw?=?draw
????????self.img_path?=?save_path
????????self.file_type?=?os.path.splitext(save_path)[-1].lower()
????????self.save_path_json?=?save_path.replace(self.file_type?‘.json‘)
????????self.save_path_mask?=?save_path.replace(self.file_type?‘.jpg‘)
????????self.img_show?=?img.copy()
????????self.cls?=?0
????????self.annotate?=?[]
????????self.alpha?=?0.7
????????self.beta?=?1?-?self.alpha
????????self.gamma?=?0
????????self.annotates?=?[]

????def?draw_rectangle(self?event?x?y?flags?param):
????????if?event?==?cv2.EVENT_LBUTTONDBLCLK:
????????????if?len(self.annotate)?>?0:
????????????????if?((x?-?self.annotate[0][0])?**?2?+?(y?-?self.annotate[0][1])?**?2?????????????????????(x?y)?=?self.annotate[0]
????????????????????self.draw?=?True
????????????self.annotate.append((x?y))
????????????if?self.draw?==?True:
????????????????self.annotates.append([self.cls?self.annotate])
????????????????self.annotate?=?[]
????????????#?print(self.annotate)
????????????#?self.start_x?self.start_y?=?x?y

????????elif?flags?==?cv2.EVENT_FLAG_CTRLKEY?+?cv2.EVENT_LBUTTONDOWN:
????????????self.cls?+=?1
????????????#?print(‘Current?cls:%d‘?%?(self.cls))
????????elif?flags?==?cv2.EVENT_FLAG_CTRLKEY?+?cv2.EVENT_RBUTTONDOWN:
????????????if?self.cls?>=?1:
????????????????self.cls?-=?1
????????????else:
????????????????self.cls?=?0
????????????#?print(‘Current?cls:%d‘?%?(self.cls))

????def?draw_window(self):
????????cv2.namedWindow(‘image‘?2)
????????cv2.setMouseCallback(‘image‘?self.draw_rectangle)
????????while?True:
????????????#?annotate?=?np.array(self.annotate)
????????????img_show?=?self.img_copy.copy()
????????????for?i?in?range(len(self.annotate)):
????????????????cv2.circle(img_show?self.annotate[i]?1?(0?255?255)?-1)
????????????for?i?in?range(len(self.annotate)?-?1):
????????????????cv2.line(img_show?self.annotate[i]?self.annotate[i?+?1]?(0?255?255)?10)
????????????self.img_show?=?img_show
????????????for?cls?annotate?in?self.annotates:
????????????????for?i?in?range(len(annotate)?-?1):
????????????????????cv2.line(img_show?annotate[i]?annotate[i?+?1]?(0?255?255)?1)
????????????????????mask?=?cv2.polylines(img_show?[np.array(annotate)]?True?(0?255?255))
????????????????????#?cv2.imshow(‘mask‘?mask)
????????????????????mask2?=?cv2.

評論

共有 條評論