PB9控制摄像头进行拍照

190 阅读1分钟

PB9控制摄像头进行拍照

  1. 添加局部外函数

image.png

Function Long capCreateCaptureWindowA(String lpszWindowName,ULong dwStyle,Long li_x ,Long li_y ,Long nWidth ,Long nHeight ,ULong ParentWin ,Long  nId ) Library 'AVICAP32.DLL'
Function Long GetFeature(String path,Ref String feature) Library 'facerecodll.dll'
Function Double FaceMatch(String path1,String path2) Library 'facerecodll.dll'
  1. 设置实例变量

image.png

UInt lhand
Constant Long WM_USER = 1024
Constant Long WM_CAP_START = WM_USER
Constant Long WM_CAP_STOP = WM_CAP_START + 68
Constant Long WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10
Constant Long WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11
Constant Long WM_CAP_SAVEDIB = WM_CAP_START + 25
Constant Long WM_CAP_GRAB_FRAME = WM_CAP_START + 60
Constant Long WM_CAP_SEQUENCE = WM_CAP_START + 62
Constant Long WM_CAP_FILE_SET_CAPTURE_FILEA = WM_CAP_START + 20
Constant Long WM_CAP_SEQUENCE_NOFILE = WM_CAP_START+  63
Constant Long WM_CAP_SET_OVERLAY = WM_CAP_START+  51
Constant Long WM_CAP_SET_PREVIEW = WM_CAP_START+  50
Constant Long WM_CAP_SET_CALLBACK_VIDEOSTREAM = WM_CAP_START +6
Constant Long WM_CAP_SET_CALLBACK_ERROR = WM_CAP_START +2
Constant Long WM_CAP_SET_CALLBACK_STATUSA = WM_CAP_START +3
Constant Long WM_CAP_SET_CALLBACK_FRAME = WM_CAP_START +5
Constant Long WM_CAP_SET_SCALE = WM_CAP_START+  53
Constant Long WM_CAP_SET_PREVIEWRATE = WM_CAP_START+  52
Constant Long WORKBUF_SIZE = 40*1024*1024
  1. 连接摄像头设备
String	lpszName
ULong		l1

iuo_char = Create uo_char_convert

l1			= Handle(p_3)

lhand		= capCreateCaptureWindowA(lpszName,1073741824+268435456,0,0,UnitsToPixels(p_3.Width,XUnitsToPixels!),UnitsToPixels(p_3.Height,YUnitsToPixels!),l1,0)

If lhand <> 0 Then
	Send(lhand, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0)
	Send(lhand, WM_CAP_SET_CALLBACK_ERROR, 0, 0)
	Send(lhand, WM_CAP_SET_CALLBACK_STATUSA, 0, 0)
	Send(lhand, WM_CAP_DRIVER_CONNECT, 0, 0)
	Send(lhand, WM_CAP_SET_SCALE, 1, 0)
	Send(lhand, WM_CAP_SET_PREVIEWRATE, 66, 0)
	Send(lhand, WM_CAP_SET_OVERLAY, 1, 0)
	Send(lhand, WM_CAP_SET_PREVIEW, 1, 0)
End If
  1. 拍摄照片
String	s_map
String	lvs_jpg

s_map	= 'sample2.bmp'

If lhand <> 0 Then
	p_2.picturename	= ''
	Send(lhand,WM_CAP_SAVEDIB,0,s_map);
	p_2.picturename	= s_map
Else
	MessageBox('提示','请先打开摄像头')
End If
  1. 需要的dll

facerecodll.dll