hikrobot dual smart camera test OK
This commit is contained in:
parent
240373973d
commit
2d92ab9555
@ -2,6 +2,7 @@ import ctypes
|
|||||||
import json
|
import json
|
||||||
import socket
|
import socket
|
||||||
import struct
|
import struct
|
||||||
|
import time
|
||||||
from ctypes import *
|
from ctypes import *
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@ -214,13 +215,16 @@ mv_lib.MV_VS_SetEnumValue.restype = c_int
|
|||||||
mv_lib.MV_VS_StartRun.argtypes = [c_void_p] # handle
|
mv_lib.MV_VS_StartRun.argtypes = [c_void_p] # handle
|
||||||
mv_lib.MV_VS_StartRun.restype = c_int
|
mv_lib.MV_VS_StartRun.restype = c_int
|
||||||
|
|
||||||
|
mv_lib.MV_VS_SetCommandValue.argtypes = [c_void_p, c_char_p]
|
||||||
|
mv_lib.MV_VS_SetCommandValue.restype = c_int
|
||||||
|
|
||||||
def MV_VS_GetFrame(handle):
|
|
||||||
|
def MV_VS_GetFrame(handle, suffix):
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
stFrameData = MV_VS_DATA()
|
stFrameData = MV_VS_DATA()
|
||||||
|
|
||||||
nRet = mv_lib.MV_VS_GetResultData(handle, byref(stFrameData), 1000)
|
nRet = mv_lib.MV_VS_GetResultData(handle, byref(stFrameData), 2000)
|
||||||
if nRet == MV_VS_OK:
|
if nRet == MV_VS_OK:
|
||||||
# Print frame information
|
# Print frame information
|
||||||
print(
|
print(
|
||||||
@ -309,7 +313,7 @@ def MV_VS_GetFrame(handle):
|
|||||||
m_stJpgParam.nBufInputLen = stFrameData.nImageLen
|
m_stJpgParam.nBufInputLen = stFrameData.nImageLen
|
||||||
jpegContents = ctypes.string_at(m_stJpgParam.pBufInput, m_stJpgParam.nBufInputLen)
|
jpegContents = ctypes.string_at(m_stJpgParam.pBufInput, m_stJpgParam.nBufInputLen)
|
||||||
|
|
||||||
with open("tmp/test.jpg", "wb") as f:
|
with open(f"tmp/test_{suffix}.jpg", "wb") as f:
|
||||||
f.write(jpegContents)
|
f.write(jpegContents)
|
||||||
|
|
||||||
# Release frame buffer
|
# Release frame buffer
|
||||||
@ -321,3 +325,4 @@ def MV_VS_GetFrame(handle):
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
print(f"MV_VS_GetResultData fail! nRet [0x{nRet&0xFFFFFFFF:x}]")
|
print(f"MV_VS_GetResultData fail! nRet [0x{nRet&0xFFFFFFFF:x}]")
|
||||||
|
time.sleep(500)
|
||||||
|
|||||||
@ -44,13 +44,13 @@ def main():
|
|||||||
print("Starting dual camera test!")
|
print("Starting dual camera test!")
|
||||||
# Define MV_VS_OK (replace with the actual value)
|
# Define MV_VS_OK (replace with the actual value)
|
||||||
MV_VS_OK = 0
|
MV_VS_OK = 0
|
||||||
MV_VS_DEVICE_INFO_1 = device_info_list.pDeviceInfo[0];
|
MV_VS_DEVICE_INFO_1 = device_info_list.pDeviceInfo[0]
|
||||||
MV_VS_DEVICE_INFO_2 = device_info_list.pDeviceInfo[1];
|
MV_VS_DEVICE_INFO_2 = device_info_list.pDeviceInfo[1]
|
||||||
pHandle1 = c_void_p()
|
pHandle1 = c_void_p()
|
||||||
pHandle2 = c_void_p()
|
pHandle2 = c_void_p()
|
||||||
nRet1 = mv_lib.MV_VS_CreateHandle(byref(pHandle1), MV_VS_DEVICE_INFO_1)
|
nRet1 = mv_lib.MV_VS_CreateHandle(byref(pHandle1), MV_VS_DEVICE_INFO_1)
|
||||||
nRet2=0
|
nRet2=0
|
||||||
#nRet2 = mv_lib.MV_VS_CreateHandle(byref(pHandle2), MV_VS_DEVICE_INFO_2)
|
nRet2 = mv_lib.MV_VS_CreateHandle(byref(pHandle2), MV_VS_DEVICE_INFO_2)
|
||||||
if nRet1 != MV_VS_OK or nRet2 != MV_VS_OK:
|
if nRet1 != MV_VS_OK or nRet2 != MV_VS_OK:
|
||||||
print(f"Create Handle failed! [{nRet1:#x} {nRet2:#x}]")
|
print(f"Create Handle failed! [{nRet1:#x} {nRet2:#x}]")
|
||||||
return
|
return
|
||||||
@ -58,7 +58,7 @@ def main():
|
|||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
nRet1 = mv_lib.MV_VS_Login(pHandle1, b"Admin", b"Abc1234")
|
nRet1 = mv_lib.MV_VS_Login(pHandle1, b"Admin", b"Abc1234")
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
#nRet2 = mv_lib.MV_VS_Login(pHandle2, b"Admin", b"Abc1234")
|
nRet2 = mv_lib.MV_VS_Login(pHandle2, b"Admin", b"Abc1234")
|
||||||
if nRet1 != MV_VS_OK or nRet2 != MV_VS_OK:
|
if nRet1 != MV_VS_OK or nRet2 != MV_VS_OK:
|
||||||
print(f"Login failed! [{nRet1&0xFFFFFFFF:#x} {nRet2&0xFFFFFFFF:#x}]")
|
print(f"Login failed! [{nRet1&0xFFFFFFFF:#x} {nRet2&0xFFFFFFFF:#x}]")
|
||||||
return
|
return
|
||||||
@ -66,7 +66,7 @@ def main():
|
|||||||
print("Login OK")
|
print("Login OK")
|
||||||
|
|
||||||
nRet1 = mv_lib.MV_VS_SetBoolValue(pHandle1, b"CommandImageMode", 0)
|
nRet1 = mv_lib.MV_VS_SetBoolValue(pHandle1, b"CommandImageMode", 0)
|
||||||
#nRet2 = mv_lib.MV_VS_SetBoolValue(pHandle2, b"CommandImageMode", 0)
|
nRet2 = mv_lib.MV_VS_SetBoolValue(pHandle2, b"CommandImageMode", 0)
|
||||||
if nRet1 != MV_VS_OK or nRet2 != MV_VS_OK:
|
if nRet1 != MV_VS_OK or nRet2 != MV_VS_OK:
|
||||||
print(f"CommandImageMode failed! [{nRet1&0xFFFFFFFF:#x} {nRet2&0xFFFFFFFF:#x}]")
|
print(f"CommandImageMode failed! [{nRet1&0xFFFFFFFF:#x} {nRet2&0xFFFFFFFF:#x}]")
|
||||||
return
|
return
|
||||||
@ -74,13 +74,17 @@ def main():
|
|||||||
print("CommandImageMode OK")
|
print("CommandImageMode OK")
|
||||||
|
|
||||||
nRet1 = mv_lib.MV_VS_SetEnumValue(pHandle1, b"AcquisitionMode", 0)
|
nRet1 = mv_lib.MV_VS_SetEnumValue(pHandle1, b"AcquisitionMode", 0)
|
||||||
#nRet2 = mv_lib.MV_VS_SetEnumValue(pHandle2, b"AcquisitionMode", 0)
|
nRet2 = mv_lib.MV_VS_SetEnumValue(pHandle2, b"AcquisitionMode", 0)
|
||||||
if nRet1 != MV_VS_OK or nRet2 != MV_VS_OK:
|
if nRet1 != MV_VS_OK or nRet2 != MV_VS_OK:
|
||||||
print(f"AcquisitionMode failed! [{nRet1&0xFFFFFFFF:#x} {nRet2&0xFFFFFFFF:#x}]")
|
print(f"AcquisitionMode failed! [{nRet1&0xFFFFFFFF:#x} {nRet2&0xFFFFFFFF:#x}]")
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
print("AcquisitionMode OK")
|
print("AcquisitionMode OK")
|
||||||
|
|
||||||
|
# Start the camera test
|
||||||
|
nRet1 = mv_lib.MV_VS_StartRun(pHandle1)
|
||||||
|
nRet2 = mv_lib.MV_VS_StartRun(pHandle2)
|
||||||
|
|
||||||
stMemory = PROCESS_MEMORY_COUNTERS()
|
stMemory = PROCESS_MEMORY_COUNTERS()
|
||||||
ctypes.windll.psapi.GetProcessMemoryInfo(
|
ctypes.windll.psapi.GetProcessMemoryInfo(
|
||||||
ctypes.windll.kernel32.GetCurrentProcess(), ctypes.byref(stMemory), ctypes.sizeof(stMemory)
|
ctypes.windll.kernel32.GetCurrentProcess(), ctypes.byref(stMemory), ctypes.sizeof(stMemory)
|
||||||
@ -96,16 +100,13 @@ def main():
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Create the thread
|
# Create the thread
|
||||||
thread = threading.Thread(target=MV_VS_GetFrame, args=(pHandle1,))
|
thread = threading.Thread(target=MV_VS_GetFrame, args=(pHandle1, "dx"))
|
||||||
thread2 = threading.Thread(target=MV_VS_GetFrame, args=(pHandle2,))
|
thread2 = threading.Thread(target=MV_VS_GetFrame, args=(pHandle2, "sx"))
|
||||||
|
|
||||||
# Start the thread
|
# Start the thread
|
||||||
thread.start()
|
thread.start()
|
||||||
#thread2.start()
|
thread2.start()
|
||||||
|
|
||||||
#Start the camera test
|
|
||||||
nRet1 = mv_lib.MV_VS_StartRun(pHandle1)
|
|
||||||
#nRet2 = mv_lib.MV_VS_StartRun(pHandle2)
|
|
||||||
if nRet1 != MV_VS_OK or nRet2 != MV_VS_OK:
|
if nRet1 != MV_VS_OK or nRet2 != MV_VS_OK:
|
||||||
print(f"Start run failed! [{nRet1 & 0xFFFFFFFF:#x} {nRet2 & 0xFFFFFFFF:#x}]")
|
print(f"Start run failed! [{nRet1 & 0xFFFFFFFF:#x} {nRet2 & 0xFFFFFFFF:#x}]")
|
||||||
|
|
||||||
@ -113,8 +114,8 @@ def main():
|
|||||||
print("main loop cycle")
|
print("main loop cycle")
|
||||||
|
|
||||||
#Trigger acquisition & test execution
|
#Trigger acquisition & test execution
|
||||||
nRet1 = mv_lib.MV_VS_SetCommandValue(pHandle1, "AcquisitionStart")
|
nRet1 = mv_lib.MV_VS_SetCommandValue(pHandle1, b"AcquisitionStart")
|
||||||
#nRet2 = mv_lib.MV_VS_SetCommandValue(pHandle2, "AcquisitionStart")
|
nRet2 = mv_lib.MV_VS_SetCommandValue(pHandle2, b"AcquisitionStart")
|
||||||
if nRet1 != MV_VS_OK or nRet2 != MV_VS_OK:
|
if nRet1 != MV_VS_OK or nRet2 != MV_VS_OK:
|
||||||
print(f"AcquisitionStart failed! [{nRet1 & 0xFFFFFFFF:#x} {nRet2 & 0xFFFFFFFF:#x}]")
|
print(f"AcquisitionStart failed! [{nRet1 & 0xFFFFFFFF:#x} {nRet2 & 0xFFFFFFFF:#x}]")
|
||||||
else:
|
else:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user