EasyMocap/easymocap/socket/utils.py

28 lines
959 B
Python
Raw Normal View History

'''
@ Date: 2021-05-24 20:07:34
@ Author: Qing Shuai
@ LastEditors: Qing Shuai
2021-06-25 21:17:22 +08:00
@ LastEditTime: 2021-06-16 14:42:23
@ FilePath: /EasyMocap/easymocap/socket/utils.py
'''
import cv2
import numpy as np
from ..mytools.file_utils import write_common_results
def encode_detect(data):
res = write_common_results(None, data, ['keypoints3d'])
res = res.replace('\r', '').replace('\n', '').replace(' ', '')
return res.encode('ascii')
2021-06-25 21:17:22 +08:00
def encode_smpl(data):
res = write_common_results(None, data, ['poses', 'shapes', 'Rh', 'Th'])
res = res.replace('\r', '').replace('\n', '').replace(' ', '')
return res.encode('ascii')
def encode_image(image):
fourcc = [int(cv2.IMWRITE_JPEG_QUALITY), 90]
#frame을 binary 형태로 변환 jpg로 decoding
result, img_encode = cv2.imencode('.jpg', image, fourcc)
data = np.array(img_encode) # numpy array로 안바꿔주면 ERROR
stringData = data.tostring()
return stringData