ASVL_PAF_RGB24_B8G8R8 格式转换

完整代码参考:https://github.com/xihaban/uml-/blob/34521c5815e798038821c79c0e7412eb04537286/fr/arcsoft/utils/ImageLoader.py 

ASVL_PAF_RGB24_B8G8R8个人感觉就是bmp格式
  oldimg = Image.open(filePath)

     # BMP 4 byte align
    newWidth = oldimg.width& 0xFFFFFFFC
    newHeight = oldimg.height& 0xFFFFFFFE
    if(newWidth != oldimg.width) or (newHeight != oldimg.height):
        crop_area = (0, 0, newWidth, newHeight)
        img = oldimg.crop(crop_area)
    else:
        img = oldimg

    BMP_bytes = io.BytesIO()
    img.transpose(Image.FLIP_TOP_BOTTOM).convert('RGB').save(BMP_bytes, format='BMP')
    bgr_buffer = bytes(BMP_bytes.getvalue()[54:])

代码没试:

https://www.cnblogs.com/wxt51/p/10111536.html

#调用dll需要引入ctypes
from ctypes import *
from face_class import *
import io
from PIL import Image
import cv2
dll=CDLL('d:\python\Test\Face\lib\X64\libarcsoft_face.dll')
Facedll=CDLL('d:\python\Test\Face\lib\X64\libarcsoft_face_engine.dll')
#由于dll是c,所以字符串要做类型转换,否则,激活失败,APPID无效
Appkey=c_char_p(b'自己去注册')
SDKey=c_char_p(b'自己去注册')
# ASF_VERSION a=Facedll.ASFActiviation(Appkey,SDKey)
vs=Facedll.ASFActivation
#激活函数返回0,初始化成功,返回90114已激活,其他则为失败 ,重新激活需删除asf_install.dat 文件
ret=Facedll.ASFActivation(Appkey,SDKey)
print('激活:',ret)
#初始化引擎
ASF_OP_0_ONLY = 0x1
ASF_DETECT_MODE_VIDEO = 0x00000000
ASF_DETECT_MODE_IMAGE = 0xFFFFFFFF
r=c_void_p()
#初始化引擎
a=Facedll.ASFInitEngine(c_long(ASF_DETECT_MODE_IMAGE),c_int32(ASF_OP_0_ONLY),c_int32(16),c_int32(50),c_int8(ASF_OP_0_ONLY),byref(r))
print('初始化',a)
print('初始化返回',r)
c_ubyte_p = POINTER(c_ubyte) 
ASVL_PAF_I420 = 0x601
ASVL_PAF_RGB24_B8G8R8 = 0x201
img1=cv2.imread('e:/5.jpg')
sp=img1.shape
#调整图片大小,正好是4的倍数,否则会报错
img=cv2.resize(img1,(sp[1]//4*4,sp[0]//4*4))
# img=cv2.cvtColor(img,cv2.COLOR_BGR2YUV_I420)
# img=cv2.cvtColor(img,cv2.COLOR_BGRA2YUV_I420)
# img=cv2.cvtColor(img,cv2.COLOR_BGR2YUV_IYUV)
sp=img.shape
wd=sp[1]
he=sp[0]
print('宽高',wd,he)
# cv2.imshow('1',img)
# cv2.waitKey(0)
#内存指针返回ASF_MultiFaceInfo类型--回调函数
tz=POINTER(ASF_MultiFaceInfo)()
#图片转换成字字节
b=bytes(img)
#强转为C++的byte类型
d=cast(b,c_ubyte_p)
#调用多人人脸识别
a=Facedll.ASFDetectFaces(r,c_int32(wd),c_int32(he),c_int32(ASVL_PAF_RGB24_B8G8R8),d,byref(tz))
print('返回特征',tz)
print('返回值',a)
if a==0:
    tezheng=tz.contents
    print(tezheng.faceNum)
    for i in range(0,50):
        # cv2.rectangle(img,(tezheng.faceRect[1].left1,tezheng.faceRect[1].top1),(tezheng.faceRect[1].right1,tezheng.faceRect[1].bottom1),(255,0,0),2)
        cv2.rectangle(img,(tezheng.faceRect[i].left1,tezheng.faceRect[i].top1),(tezheng.faceRect[i].right1,tezheng.faceRect[i].bottom1),(255,0,0),2)
    cv2.imshow('1',img)
    cv2.waitKey(0)
发布了2718 篇原创文章 · 获赞 1004 · 访问量 536万+

猜你喜欢

转载自blog.csdn.net/jacke121/article/details/104615680
今日推荐