Skip to content

Commit 3c4db66

Browse files
authored
Update transforms.py
1 parent 0e401f5 commit 3c4db66

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

Matting/ppmatting/transforms/transforms.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -782,10 +782,10 @@ def __call__(self, data):
782782
q = np.random.randint(70, 95)
783783
img = data['img'].astype('uint8')
784784

785-
# Ensure no conflicts between processes
786-
tmp_name = str(os.getpid()) + '.jpg'
787-
tmp_name = os.path.join(seg_env.TMP_HOME, tmp_name)
788-
cv2.imwrite(tmp_name, img, [int(cv2.IMWRITE_JPEG_QUALITY), q])
789-
data['img'] = cv2.imread(tmp_name)
785+
# 直接在内存上实现JPEG压缩
786+
encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), q]
787+
result, encoded_img = cv2.imencode('.jpg', img, encode_param)
788+
if result:
789+
data['img'] = cv2.imdecode(encoded_img, cv2.IMREAD_COLOR)
790790

791791
return data

0 commit comments

Comments
 (0)