提交 c05363f6 编写于 作者: HypoX64's avatar HypoX64

update_to_OpenCV_4.0

上级 bbfa93a8
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
...@@ -107,20 +107,11 @@ def mask_threshold(mask,blur,threshold): ...@@ -107,20 +107,11 @@ def mask_threshold(mask,blur,threshold):
return mask return mask
def mask_area(mask): def mask_area(mask):
contours= cv2.findContours(mask,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)[1] mask = cv2.threshold(mask,127,255,0)[1]
# contours= cv2.findContours(mask,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)[1] #for opencv 3.4
contours= cv2.findContours(mask,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)[0]#updata to opencv 4.0
try: try:
area = cv2.contourArea(contours[0]) area = cv2.contourArea(contours[0])
except: except:
area = 0 area = 0
return area return area
# def eclosion_add(img_fg,img_bg,mask,eclosion_num,Type = 'inside'):
# mask = (cv2.blur(mask, (eclosion, eclosion)))
# mask = ch_one2three(mask)
# mask = mask/255.0
# # img_tmp = np.zeros(img_bg.shape, dtype='uint8')
# # img_tmp[y-size:y+size,x-size:x+size]=img_fake
# img_result = img_origin.copy()
# img_result = img_origin*(1-mask)+img_tmp*mask
\ No newline at end of file
...@@ -2,7 +2,7 @@ import cv2 ...@@ -2,7 +2,7 @@ import cv2
import numpy as np import numpy as np
import os import os
import random import random
from .image_processing import resize,ch_one2three from .image_processing import resize,ch_one2three,mask_area
def addmosaic(img,mask,n,out_size = 0,model = 'squa_avg'): def addmosaic(img,mask,n,out_size = 0,model = 'squa_avg'):
...@@ -10,7 +10,6 @@ def addmosaic(img,mask,n,out_size = 0,model = 'squa_avg'): ...@@ -10,7 +10,6 @@ def addmosaic(img,mask,n,out_size = 0,model = 'squa_avg'):
img = resize(img,out_size) img = resize(img,out_size)
h, w = img.shape[:2] h, w = img.shape[:2]
mask = cv2.resize(mask,(w,h)) mask = cv2.resize(mask,(w,h))
img_mosaic=img.copy() img_mosaic=img.copy()
if model=='squa_avg': if model=='squa_avg':
...@@ -64,9 +63,8 @@ def random_mosaic(img,mask): ...@@ -64,9 +63,8 @@ def random_mosaic(img,mask):
h,w = img.shape[:2] h,w = img.shape[:2]
mask = cv2.resize(mask,(w,h)) mask = cv2.resize(mask,(w,h))
#area_avg=5925*4 #area_avg=5925*4
image, contours, hierarchy = cv2.findContours(mask,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
try: try:
area = cv2.contourArea(contours[0]) area = mask_area(mask)
except: except:
area = 0 area = 0
if area>50000: if area>50000:
......
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册