import cv2
from datetime import datetime
import time
import numpy as np
from turbojpeg import TurboJPEG
jpeg = TurboJPEG("/root/test/libturbojpeg.so") # 使用绝对路径
def fun(out_file_name):
width = 1920
height = 1080
with open("1.rgb", "rb") as in_file:
input_buff = in_file.read()
buf_data = np.frombuffer(input_buff, dtype=np.uint8)
raw_img = buf_data.reshape((height, width, 3)).copy()
t_start = time.perf_counter()
loop = 1
for _ in range(loop):
cv2.putText(raw_img, datetime.now().strftime("%Y-%m-%d %H:%M:%S"), (40, 90), cv2.FONT_HERSHEY_SIMPLEX, 1.2, (0, 0, 0), 3)
t_end = time.perf_counter()
print(f"[{out_file_name}][{loop} times ]cost=====================: {(t_end - t_start)*1000*1000/loop:.0f} us")
raw_img = cv2.cvtColor(raw_img, cv2.COLOR_BGR2RGB)
encoded_img = jpeg.encode(raw_img, quality=85)
with open(out_file_name, "wb") as out_file:
out_file.write(encoded_img)
if __name__ == "__main__":
fun("1.jpg")