update
This commit is contained in:
@ -43,7 +43,7 @@ def analysis_video(model, video_path, result_path, uuid_barcode, maskpath=None,
|
||||
search_r = ManagingFeature().getfeature(barcode)
|
||||
#print('search_r>>>>>>>>', len(search_r))
|
||||
ori_mask = cv2.imread(maskpath, 0)
|
||||
nn, nu = 0, 1
|
||||
nn, nu, result = 0, 1, None
|
||||
Result = '03'
|
||||
img_dic = {}
|
||||
ex_ocrList, resultList = [],[]
|
||||
@ -87,16 +87,17 @@ def analysis_video(model, video_path, result_path, uuid_barcode, maskpath=None,
|
||||
|
||||
flow_low, flow_up = model(image1, image2, iters=2, test_mode=True)
|
||||
flo = viz(image1, flow_up)
|
||||
result = get_target(result_path, flo, imfile1, nu, ori_mask, uuid_barcode, MASKIMG)
|
||||
result,coordination = get_target(result_path, flo, imfile1, nu, ori_mask, uuid_barcode, MASKIMG)
|
||||
imfile1 = imfile2
|
||||
flag, nu, Result = detect(match, affd, net, result, transform, ms, search_r, nn, nu, Result)
|
||||
if flag: break
|
||||
Addimg_content(uuid_barcode, frame_show)#图片上传
|
||||
#if not Result=='03':
|
||||
if result is not None:
|
||||
cv2.imwrite(os.sep.join([cfg.Ocrimg, uuid_barcode+'_'+str(nu)+'.jpg']), result) #give ocr img
|
||||
coordinate = str(coordination[0])+'_'+str(coordination[1])+'_'+str(coordination[2])+'_'+str(coordination[3])
|
||||
cv2.imwrite(os.sep.join([cfg.Ocrimg, uuid_barcode+'_'+str(nu)+'_'+coordinate+'.jpg']), frame_show) #give ocr img
|
||||
else:
|
||||
cv2.imwrite(os.sep.join([cfg.Ocrimg, uuid_barcode+'_'+str(nu)+'.jpg']), frame_show) #give ocr img
|
||||
cv2.imwrite(os.sep.join([cfg.Ocrimg, uuid_barcode+'_'+str(nu)+'_0_0_0_0'+'.jpg']), frame_show) #give ocr img
|
||||
return Result
|
||||
|
||||
def detect(match, affd, net, result, transform, ms, search_r, nn, nu, Result):
|
||||
@ -141,28 +142,28 @@ def get_target(path, img, ori_img, nu, ori_mask, uuid_barcode, MASKIMG):
|
||||
else:
|
||||
contours, _ = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
|
||||
if len(contours)>100:
|
||||
return None
|
||||
return None, '_'
|
||||
for contour in contours:
|
||||
mask_area_now = cv2.contourArea(contour)
|
||||
if mask_area_now > mask_max_area:
|
||||
mask_max_area = mask_area_now
|
||||
mask_max_contour = contour
|
||||
if mask_max_area == 0 :return None #mask_max_area 目标位的面积
|
||||
if mask_max_area == 0 :return None, '_' #mask_max_area 目标位的面积
|
||||
(x, y, w, h) = cv2.boundingRect(mask_max_contour)
|
||||
if (w*h)/(img.shape[0]*img.shape[1])>0.80:
|
||||
return None
|
||||
return None, '_'
|
||||
if min(w,h) <100 or max(w,h)>1000:
|
||||
return None
|
||||
return None, '_'
|
||||
coordination = [x, y, x + w, y + h]
|
||||
mask_image = cv2.fillPoly(mask_image, [mask_max_contour], (255))
|
||||
if pre_area==0:
|
||||
pre_area = mask_max_area
|
||||
return None
|
||||
return None, '_'
|
||||
else:
|
||||
if abs(mask_max_area-pre_area)/pre_area > 0.4:
|
||||
pre_area = mask_max_area
|
||||
#print('abs:',abs(mask_max_area-pre_area)/pre_area)
|
||||
return None
|
||||
return None, '_'
|
||||
else:
|
||||
pre_area = mask_max_area
|
||||
A,B,C = mask_image, mask_image, mask_image
|
||||
@ -170,13 +171,13 @@ def get_target(path, img, ori_img, nu, ori_mask, uuid_barcode, MASKIMG):
|
||||
|
||||
#该方法去除框外干扰
|
||||
if not get_iou_ratio(mask_image, MASKIMG):
|
||||
return None
|
||||
return None, '_'
|
||||
|
||||
show = cv2.bitwise_and(ori_img, mask_image)
|
||||
#show = show[coordination[1]:coordination[3], coordination[0]:coordination[2]]
|
||||
show = ori_img[coordination[1]:coordination[3], coordination[0]:coordination[2]]
|
||||
#cv2.imwrite(os.sep.join([cfg.Ocrimg, str(nu-1)+'_'+uuid_barcode+'.jpg']), show)
|
||||
return show
|
||||
return show, coordination
|
||||
|
||||
def get_iou_ratio(oimg, MASKIMG):
|
||||
mimg = cv2.imread(MASKIMG)
|
||||
|
Reference in New Issue
Block a user