How to use write_box method in Slash

Best Python code snippet using slash

detect.py

Source:detect.py Github

copy

Full Screen

1import cv22from config import config3from src.human_detection import ImgProcessor4import numpy as np5from utils.utils import write_file67write_box = False8write_video = True910frame_size = config.frame_size11store_size = config.store_size121314class RegionDetector(object):15 def __init__(self, path):16 self.path = path17 self.cap = cv2.VideoCapture(path)18 self.fgbg = cv2.createBackgroundSubtractorMOG2(history=500, varThreshold=200, detectShadows=False)19 self.IP = ImgProcessor()20 if write_box:21 self.black_file = open("video/txt/black/{}.txt".format(path.split("/")[-1][:-4]), "w")22 self.gray_file = open("video/txt/gray/{}.txt".format(path.split("/")[-1][:-4]), "w")23 self.black_score_file = open("video/txt/black_score/{}.txt".format(path.split("/")[-1][:-4]), "w")24 self.gray_score_file = open("video/txt/gray_score/{}.txt".format(path.split("/")[-1][:-4]), "w")2526 if write_video:27 self.out_video = cv2.VideoWriter("output.mp4", cv2.VideoWriter_fourcc(*'XVID'), 15, (2160, 1080))2829 def process(self):30 self.IP.object_tracker.init_tracker()31 cnt = 032 # fourcc = cv2.VideoWriter_fourcc(*'XVID')33 while True:34 ret, frame = self.cap.read()35 if ret:36 frame = cv2.resize(frame, config.frame_size)37 fgmask = self.fgbg.apply(frame)38 background = self.fgbg.getBackgroundImage()3940 gray_res, black_res, dip_res, res_map = self.IP.process_img(frame, background)4142 if write_box:43 write_file(gray_res, self.gray_file, self.gray_score_file)44 write_file(black_res, self.black_file, self.black_score_file)4546 if write_video:47 self.out_video.write(res_map)4849 cv2.imshow("res", cv2.resize(res_map, (1440, 720)))50 # out.write(res)51 cnt += 152 cv2.waitKey(1)53 else:54 self.cap.release()55 self.out_video.release()56 cv2.destroyAllWindows()57 # self.IP.RP.out.release()58 break596061if __name__ == '__main__':62 # for path in os.listdir(config.video_path):63 # for name in os.listdir(config.video_path+'/'+path):64 # aa = config.video_path+'/'+path+'/'+name65 # print(aa)66 # RD = RegionDetector(config.video_path)67 # RD.process()6869 import shutil70 import os71 # src = "video/619_Big Group"72 # for folder in os.listdir(src):73 # video_folder = os.path.join(src, folder)74 video_folder = "D:/0619_BIG"75 dest_folder = video_folder + "_res"76 os.makedirs(dest_folder, exist_ok=True)7778 for v_name in os.listdir(video_folder):79 video = os.path.join(video_folder, v_name)80 RD = RegionDetector(video)81 RD.process()8283 # shutil.copy("output2.mp4", os.path.join(dest_folder, "rd_" + v_name)) ...

Full Screen

Full Screen

format_transfer.py

Source:format_transfer.py Github

copy

Full Screen

...21 ),22 E.segmented(0),23 )24 return anno_tree25 def write_box(self, tree, xmin, ymin, xmax, ymax):26 E = objectify.ElementMaker(annotate=False)27 subtree = E.object(28 E.name('water'),29 E.pose('Unspecified'),30 E.truncated(0),31 E.difficult(0),32 E.bndbox(33 E.xmin(xmin),34 E.ymin(ymin),35 E.xmax(xmax),36 E.ymax(ymax)37 )38 )39 tree.append(subtree)40 return tree41 def txt2xml(self,txt,xml_outpath='./'):42 if not os.path.exists(xml_outpath):43 os.mkdir(xml_outpath)44 f=open(txt,'r')45 while True:46 line=f.readline()[:-1]47 if not line:48 break49 # write your transform code here.50 line_list=line.split(' ')51 xml_name=line_list[0].split('/')[1][:-3]+'xml'52 if len(line_list) >1: # means have bbox53 tree=self.init_xml(line_list[0])54 for box_id in range(0,int((len(line_list)-2)/5)):55 bbox = [int(i) for i in line_list[2+box_id*5:6+box_id*5]]56 tree = self.write_box(tree,bbox[0],bbox[1],bbox[2],bbox[3])57 else:58 tree=self.init_xml(line_list[0])59 etree.ElementTree(tree).write(os.path.join(xml_outpath,xml_name),pretty_print=True)60transform=FormTransForm()61for i in range(1,8):62 transform.txt2xml(txt='D:/data/Camera_pred/20190719_line10_camera/20190719_model/Camera{}_yes.txt'.format(i),...

Full Screen

Full Screen

textgrid_utils.py

Source:textgrid_utils.py Github

copy

Full Screen

1from typing import Tuple2def write_box(file, id: int, start: float, end: float, text: str) -> None:3 file.write("\t\tintervals[" + str(id) + "]:\n")4 file.write("\t\t\txmin = " + str(start) + "\n")5 file.write("\t\t\txmax = " + str(end) + "\n")6 file.write('\t\t\ttext = "' + text + '"\n')7def write_textgrid(filename, first_tier, second_tier, x_min, xmax):8 fout = open(filename, "w", encoding="utf8")9 header = (10 'File type = "ooTextFile"\nObject class = "TextGrid"\n\nxmin = '11 + str(x_min)12 + "\nxmax = "13 + str(xmax)14 + "\ntiers? <exists> \nsize = 2\n"15 )16 fout.write(header)17 # First tier18 firstTierHeader = (19 'item []: \n\titem [1]:\n\t\tclass = "IntervalTier"\n\t\tname = "Words" \n\t\txmin = 0 \n\t\txmax = '20 + str(xmax)21 + "\n"22 )23 fout.write(firstTierHeader)24 fout.write("\t\tintervals: size = " + str(len(first_tier)) + "\n")25 26 prev = x_min27 for i, info in enumerate(first_tier):28 write_box(fout, i + 1, prev, info[0], info[1])29 prev = info[0]30 31 # Second tier32 secondTierHeader = (33 '\titem [2]:\n\t\tclass = "IntervalTier"\n\t\tname = "Phones" \n\t\txmin = '34 + str(x_min)35 + "\n\t\txmax = "36 + str(xmax)37 + "\n"38 )39 fout.write("\n" + secondTierHeader)40 fout.write("\t\tintervals: size = " + str(len(second_tier)) + "\n")41 prev = x_min42 for i, info in enumerate(second_tier):43 write_box(fout, i + 1, prev, info[0], info[1])44 prev = info[0]...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful