小言_互联网的博客

虹软人证

560人阅读  评论(0)

python组建数据结构

https://github.com/xihaban/uml-/tree/34521c5815e798038821c79c0e7412eb04537286/fr/arcsoft

地址:https://uzshare.com/view/783128

调用:


  
  1. from arcsoft import CLibrary, ASVL_COLOR_FORMAT, ASVLOFFSCREEN,c_ubyte_p,FaceInfo
  2. from arcsoft.utils import BufferInfo, ImageLoader
  3. from arcsoft.AFD_FSDKLibrary import *
  4. from ctypes import *
  5. import traceback
  6. import cv2
  7. import time
  8. APPID = c_char_p( b'your id')
  9. FD_SDKKEY = c_char_p( b'your key')
  10. FD_WORKBUF_SIZE = 20 * 1024 * 1024
  11. MAX_FACE_NUM = 50
  12. bUseYUVFile = False
  13. bUseBGRToEngine = True
  14. def doFaceDetection(hFDEngine, inputImg): #对图像中的人脸进行定位
  15. faceInfo = []
  16. pFaceRes = POINTER(AFD_FSDK_FACERES)()
  17. ret = AFD_FSDK_StillImageFaceDetection(hFDEngine, byref(inputImg), byref(pFaceRes))
  18. #ret 为0
  19. if ret != 0:
  20. print( u'AFD_FSDK_StillImageFaceDetection 0x{0:x}'.format(ret))
  21. return faceInfo
  22. faceRes = pFaceRes.contents
  23. print( '******')
  24. facecont=faceRes.nFace #faceRes 是一个对象所以 输出会是一个地址值 而他的一个属性nface是表示的是人脸的个数
  25. print( '%d 个人脸' %facecont)
  26. if faceRes.nFace > 0:
  27. for i in range( 0, faceRes.nFace):
  28. rect = faceRes.rcFace[i]
  29. orient = faceRes.lfaceOrient[i]
  30. faceInfo.append(FaceInfo(rect.left,rect.top,rect.right,rect.bottom,orient))
  31. return faceInfo
  32. def loadImage(filePath):
  33. inputImg = ASVLOFFSCREEN()
  34. if bUseBGRToEngine: #true
  35. bufferInfo = ImageLoader.getBGRFromFile(filePath)
  36. inputImg.u32PixelArrayFormat = ASVL_COLOR_FORMAT.ASVL_PAF_RGB24_B8G8R8
  37. inputImg.i32Width = bufferInfo.width
  38. inputImg.i32Height = bufferInfo.height
  39. inputImg.pi32Pitch[ 0] = bufferInfo.width* 3
  40. inputImg.ppu8Plane[ 0] = cast(bufferInfo.buffer, c_ubyte_p)
  41. inputImg.ppu8Plane[ 1] = cast( 0, c_ubyte_p)
  42. inputImg.ppu8Plane[ 2] = cast( 0, c_ubyte_p)
  43. inputImg.ppu8Plane[ 3] = cast( 0, c_ubyte_p)
  44. else:
  45. bufferInfo = ImageLoader.getI420FromFile(filePath)
  46. inputImg.u32PixelArrayFormat = ASVL_COLOR_FORMAT.ASVL_PAF_I420
  47. inputImg.i32Width = bufferInfo.width
  48. inputImg.i32Height = bufferInfo.height
  49. inputImg.pi32Pitch[ 0] = inputImg.i32Width
  50. inputImg.pi32Pitch[ 1] = inputImg.i32Width // 2
  51. inputImg.pi32Pitch[ 2] = inputImg.i32Width // 2
  52. inputImg.ppu8Plane[ 0] = cast(bufferInfo.buffer, c_ubyte_p)
  53. inputImg.ppu8Plane[ 1] = cast(addressof(inputImg.ppu8Plane[ 0].contents) + (inputImg.pi32Pitch[ 0] * inputImg.i32Height), c_ubyte_p)
  54. inputImg.ppu8Plane[ 2] = cast(addressof(inputImg.ppu8Plane[ 1].contents) + (inputImg.pi32Pitch[ 1] * inputImg.i32Height // 2), c_ubyte_p)
  55. inputImg.ppu8Plane[ 3] = cast( 0, c_ubyte_p)
  56. inputImg.gc_ppu8Plane0 = bufferInfo.buffer
  57. return inputImg
  58. if __name__ == u'__main__':
  59. t=time.time()
  60. print( u'#####################################################')
  61. # init Engine
  62. pFDWorkMem = CLibrary.malloc(c_size_t(FD_WORKBUF_SIZE))
  63. hFDEngine = c_void_p()
  64. ret = AFD_FSDK_InitialFaceEngine(APPID, FD_SDKKEY, pFDWorkMem, c_int32(FD_WORKBUF_SIZE), byref(hFDEngine), AFD_FSDK_OPF_0_HIGHER_EXT, 32, MAX_FACE_NUM)
  65. #ret 为0
  66. if ret != 0:
  67. CLibrary.free(pFDWorkMem)
  68. print( u'AFD_FSDK_InitialFaceEngine ret 0x{:x}'.format(ret))
  69. exit( 0)
  70. #--------------------------------以上部分两个函数以及主函数的几条语句不变-----------------------------------------------------------
  71. filePath = '001.jpg'
  72. inputImg = loadImage(filePath) #调用loadImage函数 返回一种格式(目前还不知道这种格式是什么)
  73. frame=cv2.imread(filePath)
  74. # do Face Detect
  75. faceInfos = doFaceDetection(hFDEngine, inputImg) #调用dofaceDetection函数 进行图像处理检测人脸
  76. #print('faceInfos %s'% faceInfos[0])
  77. for i in range( 0, len(faceInfos)):
  78. rect = faceInfos[i]
  79. print( u'{} ({} {} {} {}) orient {}'.format(i, rect.left, rect.top, rect.right, rect.bottom, rect.orient))
  80. cv2.rectangle(frame, (rect.left, rect.top), (rect.right, rect.bottom), ( 0, 0, 255), 2)
  81. cropimg=frame[rect.top:rect.bottom,rect.left:rect.right] # 使用opencv裁剪照片 把人脸的照片裁剪下来
  82. cv2.imwrite( 'crop-photo/'+str(i)+ '.jpg',cropimg) # 把人脸照片保存下来
  83. AFD_FSDK_UninitialFaceEngine(hFDEngine) # release Engine
  84. cv2.imshow( 'tuxiang',frame)
  85. cv2.waitKey( 1)
  86. print( '所用时间为{} '.format(time.time()-t)) #不进行保存图片 0.12s 保存图片0.16s
  87. time.sleep( 1)
  88. CLibrary.free(pFDWorkMem)
  89. print( u'#####################################################')

 


转载:https://blog.csdn.net/jacke121/article/details/104616397
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场