diff --git a/detect.py b/detect.py index 5524272..eb55660 100644 --- a/detect.py +++ b/detect.py @@ -1,7 +1,7 @@ import argparse import time from pathlib import Path -import numpy as np + import cv2 import torch import torch.backends.cudnn as cudnn @@ -61,14 +61,6 @@ def detect(opt, save_img=False): model(torch.zeros(1, 3, imgsz, imgsz).to(device).type_as(next(model.parameters()))) # run once t0 = time.time() for path, img, im0s, vid_cap in dataset: - #MASK - site = np.array([[[0, 1024], [0, 571], [313, 365], [949, 367], [1277, 596], [1280, 1024]]], dtype=np.int32) - im = np.zeros(img.shape[:2], dtype="uint8") - cv2.polylines(im, site, 1, 255) - cv2.fillPoly(im, site, 255) - mask = im - masked = cv2.bitwise_or(img, img, mask=mask) - img = masked img = torch.from_numpy(img).to(device) img = img.half() if half else img.float() # uint8 to fp16/32 img /= 255.0 # 0 - 255 to 0.0 - 1.0 @@ -158,8 +150,7 @@ def detect(opt, save_img=False): "6923644272159", "6924882486100", "6956511907458"] targets = [] for target in pred[0]: - targets.append({"Class": names[int(target[5].item())], "precision": target[4].item(), - "xy1": [target[0].item(), target[1].item()], + targets.append({"Class": names[int(target[5].item())], "precision": target[4].item(), "xy1": [target[0].item(), target[1].item()], "xy2": [target[2].item(), target[3].item()]}) resu = {"TargetDetect": targets} print(resu) @@ -197,4 +188,4 @@ if __name__ == '__main__': # detect(opt) # strip_optimizer(opt.weights) # else: -# detect(opt,True) +# detect(opt,True) \ No newline at end of file diff --git a/ieemoo-ai-zhanting.py b/ieemoo-ai-zhanting.py index 24ab19f..d87fde3 100644 --- a/ieemoo-ai-zhanting.py +++ b/ieemoo-ai-zhanting.py @@ -78,6 +78,16 @@ def get_isempty(): image_path = '../module/ieemoo-ai-zhanting/imgs/1.jpg' file = open(image_path, 'wb') file.write(imgdata) + # #mask + # img = cv2.imread(image_path) + # site = np.array([[[0, 1024], [0, 571], [313, 365], [949, 367], [1277, 596], [1280, 1024]]], dtype=np.int32) + # im = np.zeros(img.shape[:2], dtype="uint8") + # cv2.polylines(im, site, 1, 255) + # cv2.fillPoly(im, site, 255) + # mask = im + # masked = cv2.bitwise_or(img, img, mask=mask) + # img0 = masked + # cv2.imwrite("../module/ieemoo-ai-zhanting/imgs/1.jpg",img0) pred = detect.detect(opt) logger.info(pred) #print('pred', pred)