|
|
|
@ -12,6 +12,7 @@ package com.example.lxcameraapi.service.IndustrialCamera.camera.hik; /**********
|
|
|
|
import MvCameraControlWrapper.*;
|
|
|
|
import MvCameraControlWrapper.*;
|
|
|
|
import com.example.lxcameraapi.conf.AppConfig;
|
|
|
|
import com.example.lxcameraapi.conf.AppConfig;
|
|
|
|
import com.example.lxcameraapi.service.IndustrialCamera.camera.CameraSaveUtil;
|
|
|
|
import com.example.lxcameraapi.service.IndustrialCamera.camera.CameraSaveUtil;
|
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.PreDestroy;
|
|
|
|
import javax.annotation.PreDestroy;
|
|
|
|
@ -32,6 +33,7 @@ import MvCameraControlWrapper.*;
|
|
|
|
import static MvCameraControlWrapper.MvCameraControl.MV_CC_EnumDevices;
|
|
|
|
import static MvCameraControlWrapper.MvCameraControl.MV_CC_EnumDevices;
|
|
|
|
import static MvCameraControlWrapper.MvCameraControlDefines.*;
|
|
|
|
import static MvCameraControlWrapper.MvCameraControlDefines.*;
|
|
|
|
@Service
|
|
|
|
@Service
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
public class HikSaveImage implements CameraSaveUtil {
|
|
|
|
public class HikSaveImage implements CameraSaveUtil {
|
|
|
|
|
|
|
|
|
|
|
|
// 设备句柄保存
|
|
|
|
// 设备句柄保存
|
|
|
|
@ -39,33 +41,33 @@ public class HikSaveImage implements CameraSaveUtil {
|
|
|
|
private static void printDeviceInfo(MV_CC_DEVICE_INFO stDeviceInfo)
|
|
|
|
private static void printDeviceInfo(MV_CC_DEVICE_INFO stDeviceInfo)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (null == stDeviceInfo) {
|
|
|
|
if (null == stDeviceInfo) {
|
|
|
|
System.out.println("stDeviceInfo is null");
|
|
|
|
log.info("stDeviceInfo is null");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (stDeviceInfo.transportLayerType == MV_GIGE_DEVICE) {
|
|
|
|
if (stDeviceInfo.transportLayerType == MV_GIGE_DEVICE) {
|
|
|
|
System.out.println("\tCurrentIp: " + stDeviceInfo.gigEInfo.currentIp);
|
|
|
|
log.info("\tCurrentIp: " + stDeviceInfo.gigEInfo.currentIp);
|
|
|
|
System.out.println("\tserialNumber: " + stDeviceInfo.gigEInfo.serialNumber);
|
|
|
|
log.info("\tserialNumber: " + stDeviceInfo.gigEInfo.serialNumber);
|
|
|
|
System.out.println("\tModel: " + stDeviceInfo.gigEInfo.modelName);
|
|
|
|
log.info("\tModel: " + stDeviceInfo.gigEInfo.modelName);
|
|
|
|
System.out.println("\tUserDefinedName: " + stDeviceInfo.gigEInfo.userDefinedName);
|
|
|
|
log.info("\tUserDefinedName: " + stDeviceInfo.gigEInfo.userDefinedName);
|
|
|
|
} else if (stDeviceInfo.transportLayerType == MV_USB_DEVICE) {
|
|
|
|
} else if (stDeviceInfo.transportLayerType == MV_USB_DEVICE) {
|
|
|
|
System.out.println("\tUserDefinedName: " + stDeviceInfo.usb3VInfo.userDefinedName);
|
|
|
|
log.info("\tUserDefinedName: " + stDeviceInfo.usb3VInfo.userDefinedName);
|
|
|
|
System.out.println("\tSerial Number: " + stDeviceInfo.usb3VInfo.serialNumber);
|
|
|
|
log.info("\tSerial Number: " + stDeviceInfo.usb3VInfo.serialNumber);
|
|
|
|
System.out.println("\tDevice Number: " + stDeviceInfo.usb3VInfo.deviceNumber);
|
|
|
|
log.info("\tDevice Number: " + stDeviceInfo.usb3VInfo.deviceNumber);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
System.err.print("Device is not supported! \n");
|
|
|
|
System.err.print("Device is not supported! \n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println("\tAccessible: "
|
|
|
|
log.info("\tAccessible: "
|
|
|
|
+ MvCameraControl.MV_CC_IsDeviceAccessible(stDeviceInfo, MV_ACCESS_Exclusive));
|
|
|
|
+ MvCameraControl.MV_CC_IsDeviceAccessible(stDeviceInfo, MV_ACCESS_Exclusive));
|
|
|
|
System.out.println("");
|
|
|
|
log.info("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static void printFrameInfo(MV_FRAME_OUT_INFO stFrameInfo)
|
|
|
|
private static void printFrameInfo(MV_FRAME_OUT_INFO stFrameInfo)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (null == stFrameInfo)
|
|
|
|
if (null == stFrameInfo)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
System.err.println("stFrameInfo is null");
|
|
|
|
log.info("stFrameInfo is null");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -75,7 +77,7 @@ public class HikSaveImage implements CameraSaveUtil {
|
|
|
|
frameInfo.append("\tHeight[" + stFrameInfo.height + "]");
|
|
|
|
frameInfo.append("\tHeight[" + stFrameInfo.height + "]");
|
|
|
|
frameInfo.append(String.format("\tPixelType[%#x]", stFrameInfo.pixelType.getnValue()));
|
|
|
|
frameInfo.append(String.format("\tPixelType[%#x]", stFrameInfo.pixelType.getnValue()));
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println(frameInfo.toString());
|
|
|
|
log.info(frameInfo.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void saveDataToFile(byte[] dataToSave, int dataSize, String fileName)
|
|
|
|
public static void saveDataToFile(byte[] dataToSave, int dataSize, String fileName)
|
|
|
|
@ -94,16 +96,16 @@ public class HikSaveImage implements CameraSaveUtil {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
System.err.println("Failed to create file: " + e.getMessage());
|
|
|
|
log.info("Failed to create file: " + e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
System.out.println("File already exists: " + path);
|
|
|
|
log.info("File already exists: " + path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 创建文件
|
|
|
|
// 创建文件
|
|
|
|
|
|
|
|
|
|
|
|
os = new FileOutputStream( fileName);
|
|
|
|
os = new FileOutputStream( fileName);
|
|
|
|
os.write(dataToSave, 0, dataSize);
|
|
|
|
os.write(dataToSave, 0, dataSize);
|
|
|
|
System.out.println("SaveImage succeed.");
|
|
|
|
log.info("SaveImage succeed.");
|
|
|
|
// Create directory
|
|
|
|
// Create directory
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -171,7 +173,7 @@ public class HikSaveImage implements CameraSaveUtil {
|
|
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
do
|
|
|
|
{
|
|
|
|
{
|
|
|
|
System.out.println("SDK Version " + MvCameraControl.MV_CC_GetSDKVersion());
|
|
|
|
log.info("SDK Version " + MvCameraControl.MV_CC_GetSDKVersion());
|
|
|
|
|
|
|
|
|
|
|
|
// Enuerate GigE and USB devices
|
|
|
|
// Enuerate GigE and USB devices
|
|
|
|
try
|
|
|
|
try
|
|
|
|
@ -179,13 +181,13 @@ public class HikSaveImage implements CameraSaveUtil {
|
|
|
|
stDeviceList = MV_CC_EnumDevices(MV_GIGE_DEVICE | MV_USB_DEVICE);
|
|
|
|
stDeviceList = MV_CC_EnumDevices(MV_GIGE_DEVICE | MV_USB_DEVICE);
|
|
|
|
if (0 >= stDeviceList.size())
|
|
|
|
if (0 >= stDeviceList.size())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
System.out.println("No devices found!");
|
|
|
|
log.info("No devices found!");
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (CameraControlException e)
|
|
|
|
catch (CameraControlException e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
System.err.println("Enumrate devices failed!" + e.toString());
|
|
|
|
log.info("Enumrate devices failed!" + e.toString());
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -224,7 +226,7 @@ public class HikSaveImage implements CameraSaveUtil {
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println("GetOneFrame: ");
|
|
|
|
log.info("GetOneFrame: ");
|
|
|
|
printFrameInfo(stImageInfo);
|
|
|
|
printFrameInfo(stImageInfo);
|
|
|
|
int imageLen = stImageInfo.width * stImageInfo.height * 3; // Every RGB pixel takes 3 bytes
|
|
|
|
int imageLen = stImageInfo.width * stImageInfo.height * 3; // Every RGB pixel takes 3 bytes
|
|
|
|
byte[] imageBuffer = new byte[imageLen];
|
|
|
|
byte[] imageBuffer = new byte[imageLen];
|
|
|
|
@ -276,7 +278,7 @@ public class HikSaveImage implements CameraSaveUtil {
|
|
|
|
|
|
|
|
|
|
|
|
nRet = MvCameraControl.MV_CC_SaveImage(hCamera, stSaveParam);
|
|
|
|
nRet = MvCameraControl.MV_CC_SaveImage(hCamera, stSaveParam);
|
|
|
|
|
|
|
|
|
|
|
|
// System.out.println("ceshi");
|
|
|
|
// log.info("ceshi");
|
|
|
|
if (MV_OK != nRet)
|
|
|
|
if (MV_OK != nRet)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
System.err.printf("SaveImage fail, errcode: [%#x]\n", nRet);
|
|
|
|
System.err.printf("SaveImage fail, errcode: [%#x]\n", nRet);
|
|
|
|
@ -302,11 +304,11 @@ public class HikSaveImage implements CameraSaveUtil {
|
|
|
|
//已经获得句柄
|
|
|
|
//已经获得句柄
|
|
|
|
hCamera = handleMap.get(sn);
|
|
|
|
hCamera = handleMap.get(sn);
|
|
|
|
}else {
|
|
|
|
}else {
|
|
|
|
System.out.println("创建句柄");
|
|
|
|
log.info("创建句柄");
|
|
|
|
camIndex = chooseCamera(stDeviceList,sn,type);
|
|
|
|
camIndex = chooseCamera(stDeviceList,sn,type);
|
|
|
|
if (camIndex == -1)
|
|
|
|
if (camIndex == -1)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
System.out.println("未找到摄像头");
|
|
|
|
log.info("未找到摄像头");
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//未获得句柄并初始化
|
|
|
|
//未获得句柄并初始化
|
|
|
|
@ -345,20 +347,20 @@ public class HikSaveImage implements CameraSaveUtil {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (CameraControlException e)
|
|
|
|
catch (CameraControlException e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
System.err.println("Create handle failed!" + e.toString());
|
|
|
|
log.info("Create handle failed!" + e.toString());
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
System.out.println(hCamera);
|
|
|
|
log.info(hCamera.toString());
|
|
|
|
return hCamera;
|
|
|
|
return hCamera;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public static void forInit(List<AppConfig.Camera> cameras){
|
|
|
|
public static void forInit(List<AppConfig.Camera> cameras){
|
|
|
|
ArrayList<MV_CC_DEVICE_INFO> stDeviceList = null;
|
|
|
|
ArrayList<MV_CC_DEVICE_INFO> stDeviceList = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println("SDK Version " + MvCameraControl.MV_CC_GetSDKVersion());
|
|
|
|
log.info("SDK Version " + MvCameraControl.MV_CC_GetSDKVersion());
|
|
|
|
|
|
|
|
|
|
|
|
// Enuerate GigE and USB devices
|
|
|
|
// Enuerate GigE and USB devices
|
|
|
|
try
|
|
|
|
try
|
|
|
|
@ -366,13 +368,13 @@ public class HikSaveImage implements CameraSaveUtil {
|
|
|
|
stDeviceList = MV_CC_EnumDevices(MV_GIGE_DEVICE );
|
|
|
|
stDeviceList = MV_CC_EnumDevices(MV_GIGE_DEVICE );
|
|
|
|
if (0 >= stDeviceList.size())
|
|
|
|
if (0 >= stDeviceList.size())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
System.out.println("No devices found!");
|
|
|
|
log.info("No devices found!");
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (CameraControlException e)
|
|
|
|
catch (CameraControlException e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
System.err.println("Enumrate devices failed!" + e.toString());
|
|
|
|
log.info("Enumrate devices failed!" + e.toString());
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|