增加3d拍照
parent
efd40fa08c
commit
5ddc663563
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,12 @@
|
||||
package com.zhehekeji.web.service.IndustrialCamera;
|
||||
|
||||
public interface CameraSaveUtil {
|
||||
/**
|
||||
*
|
||||
* @param sn sn
|
||||
* @param path 图片路径
|
||||
* @param type 暂时默认sn 后续可以添加ip等
|
||||
* @return
|
||||
*/
|
||||
boolean saveImage(String sn,String path,String type);
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
package com.zhehekeji.web.service.IndustrialCamera;
|
||||
|
||||
import com.sun.jna.Library;
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
public interface DcLibrary extends Library {
|
||||
DcLibrary INSTANCE = (DcLibrary) Native.load((System.getProperty("user.dir"))+"\\libs\\plc\\LxCameraApiR.dll", DcLibrary.class);
|
||||
// 创建一个新的实例
|
||||
|
||||
// 设备详细信息结构体
|
||||
class LxDeviceInfo extends Structure {
|
||||
public long handle; // 使用 long 类型表示 DcHandle
|
||||
public short dev_type;
|
||||
public byte[] id = new byte[32];
|
||||
public byte[] ip = new byte[32];
|
||||
public byte[] sn = new byte[32];
|
||||
public byte[] mac = new byte[32];
|
||||
public byte[] firmware_ver = new byte[32];
|
||||
public byte[] algor_ver = new byte[32];
|
||||
public byte[] name = new byte[32];
|
||||
public byte[] reserve = new byte[32];
|
||||
public byte[] reserve2 = new byte[32];
|
||||
public byte[] reserve3 = new byte[64];
|
||||
public byte[] reserve4 = new byte[128];
|
||||
|
||||
@Override
|
||||
protected List<String> getFieldOrder() {
|
||||
return Arrays.asList("handle", "dev_type", "id", "ip", "sn", "mac", "firmware_ver", "algor_ver", "name", "reserve", "reserve2", "reserve3", "reserve4");
|
||||
}
|
||||
}
|
||||
|
||||
// 设备打开函数
|
||||
int DcOpenDevice(int open_mode, String param, PointerByReference handle, LxDeviceInfo info);
|
||||
|
||||
String DcGetDeviceList(PointerByReference devlist, int devnum);
|
||||
int DcCloseDevice(Pointer handle);
|
||||
|
||||
int DcStartStream(Pointer handle);
|
||||
|
||||
int DcStopStream(Pointer handle);
|
||||
|
||||
int DcSaveXYZ(Pointer handle, String filename);
|
||||
int DcSetCmd(Pointer handle, int cmd);
|
||||
}
|
||||
// Define LX_OPEN_MODE as an enum or int based on your C definition
|
||||
@ -0,0 +1,111 @@
|
||||
package com.zhehekeji.web.service.IndustrialCamera;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Slf4j
|
||||
public class LxPointCloudSaveImage {
|
||||
|
||||
static DcLibrary INSTANCER = (DcLibrary) Native.loadLibrary((System.getProperty("user.dir"))+"\\libs\\plc\\LxCameraApiR.dll", DcLibrary.class);
|
||||
static DcLibrary INSTANCEL = (DcLibrary) Native.loadLibrary((System.getProperty("user.dir"))+"\\libs\\plc\\LxCameraApiL.dll", DcLibrary.class);
|
||||
|
||||
static Map<String, PointerByReference> handleMap = new ConcurrentHashMap<>();
|
||||
public static PointerByReference getHandle(String sn,int type ,DcLibrary INSTANCE){
|
||||
if(handleMap.get(sn)!=null){
|
||||
return handleMap.get(sn);
|
||||
}else {
|
||||
// 创建 Pointer 的引用
|
||||
PointerByReference handleRef = new PointerByReference();
|
||||
|
||||
|
||||
// 创建 PointerByReference 的实例用于接收设备列表
|
||||
// PointerByReference devlistRef = new PointerByReference();
|
||||
// 创建 LxDeviceInfo 实例
|
||||
DcLibrary.LxDeviceInfo info = new DcLibrary.LxDeviceInfo();
|
||||
|
||||
//library.DcGetDeviceList( devlistRef,0);
|
||||
|
||||
// 调用 DcOpenDevice 函数
|
||||
System.out.println(sn+" "+handleRef+" "+info);
|
||||
int result = INSTANCE.DcOpenDevice(1, sn, handleRef, info);
|
||||
int i = 0;
|
||||
if(result ==0) {
|
||||
handleMap.put(sn, handleRef);
|
||||
}else {
|
||||
for (int ii=0;i<50;i++ ) {
|
||||
result = INSTANCE.DcOpenDevice(1, sn, handleRef, info);
|
||||
System.out.println(i + "次尝试");
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 输出结果
|
||||
System.out.println("Result: " + result);
|
||||
System.out.println("Handle: " + handleRef.getValue()); // 获取 DcHandle 的值
|
||||
System.out.println("Device Type: " + info.dev_type);
|
||||
System.out.println("ID: " + new String(info.id).trim());
|
||||
System.out.println("IP: " + new String(info.ip).trim());
|
||||
System.out.println("SN: " + new String(info.sn).trim());
|
||||
System.out.println("MAC: " + new String(info.mac).trim());
|
||||
System.out.println("Firmware Version: " + new String(info.firmware_ver).trim());
|
||||
System.out.println("Algorithm Version: " + new String(info.algor_ver).trim());
|
||||
System.out.println("Name: " + new String(info.name).trim());
|
||||
System.out.println("Reserve: " + new String(info.reserve).trim());
|
||||
System.out.println("Reserve2: " + new String(info.reserve2).trim());
|
||||
System.out.println("Reserve3: " + new String(info.reserve3).trim());
|
||||
System.out.println("Reserve4: " + new String(info.reserve4).trim());//lxPointCloudApi.DcCloseDevice(handle);
|
||||
|
||||
|
||||
return handleRef;
|
||||
}
|
||||
|
||||
}
|
||||
public static boolean saveImage(String sn, String path,int type) {
|
||||
DcLibrary INSTANCE;
|
||||
if (type==1){
|
||||
INSTANCE = INSTANCER;
|
||||
}else {
|
||||
INSTANCE = INSTANCEL;
|
||||
}
|
||||
int result = 0;
|
||||
PointerByReference handleRef = getHandle(sn,type,INSTANCE);
|
||||
result = INSTANCE.DcStartStream(handleRef.getValue());
|
||||
System.out.println("Result: " + result);
|
||||
result = INSTANCE.DcSetCmd(handleRef.getValue(),5001);
|
||||
|
||||
|
||||
System.out.println("Result: " + result);
|
||||
Path path1 = Paths.get(path);
|
||||
|
||||
try {
|
||||
// 如果路径不存在,则创建目录
|
||||
Files.createDirectories(path1.getParent());
|
||||
}catch (Exception e){
|
||||
log.info("路径失败");
|
||||
}
|
||||
int i = INSTANCE.DcSaveXYZ(handleRef.getValue(), path);
|
||||
log.info(sn+" 3dCamera get pcd :"+path +";rest:"+i);
|
||||
System.out.println(sn+" 3dCamera get pcd :"+path +";rest:"+i);
|
||||
result = INSTANCE.DcStopStream(handleRef.getValue());
|
||||
|
||||
System.out.println("stop Stream Result: " + result);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
saveImage("1","E:\\1-8-2-R.pcd",1);
|
||||
|
||||
saveImage("2","E:\\12-R.pcd",2);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
package com.zhehekeji.web.service.IndustrialCamera.algorithm;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class BoxPositionConf {
|
||||
Double height;
|
||||
List<Double[]> position;
|
||||
}
|
||||
@ -0,0 +1,77 @@
|
||||
package com.zhehekeji.web.service.IndustrialCamera.algorithm;
|
||||
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
public class PCDReader {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String filePath = "path/to/your/file.pcd";
|
||||
try {
|
||||
if (isBinaryFormat(filePath)) {
|
||||
readBinaryPCD(filePath);
|
||||
} else {
|
||||
readAsciiPCD(filePath);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isBinaryFormat(String filePath) throws IOException {
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (line.startsWith("DATA")) {
|
||||
return line.contains("binary");
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void readAsciiPCD(String filePath) throws IOException {
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (!line.startsWith("#") && !line.startsWith("FIELDS") && !line.startsWith("SIZE") &&
|
||||
!line.startsWith("TYPE") && !line.startsWith("COUNT") && !line.startsWith("WIDTH") &&
|
||||
!line.startsWith("HEIGHT") && !line.startsWith("VIEWPOINT") && !line.startsWith("POINTS") &&
|
||||
!line.startsWith("DATA")) {
|
||||
String[] values = line.split(" ");
|
||||
for (String value : values) {
|
||||
System.out.println(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void readBinaryPCD(String filePath) throws IOException {
|
||||
try (FileInputStream fis = new FileInputStream(filePath)) {
|
||||
ByteBuffer buffer = ByteBuffer.wrap(fis.readAllBytes());
|
||||
buffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
// Skip header (assuming 11 lines of header; adjust if needed)
|
||||
for (int i = 0; i < 11; i++) {
|
||||
while (buffer.get() != '\n') {
|
||||
// Skip header lines
|
||||
}
|
||||
}
|
||||
// Read binary data (assuming float x, y, z and int rgb)
|
||||
while (buffer.hasRemaining()) {
|
||||
float x = buffer.getFloat();
|
||||
float y = buffer.getFloat();
|
||||
float z = buffer.getFloat();
|
||||
int rgb = buffer.getInt(); // Read 4 bytes for RGB
|
||||
System.out.printf("x: %f, y: %f, z: %f, rgb: %d%n", x, y, z, rgb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
package com.zhehekeji.web.service.IndustrialCamera.algorithm;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
@Data
|
||||
public class PcdPojo {
|
||||
|
||||
double[][] rotationMatrix = {
|
||||
{0.9982215762138367, 0.057795289903879166, 0.014606773853302002},
|
||||
{-0.0510917492210865, 0.7032182216644287, 0.7091360092163086},
|
||||
{0.030712969601154327, -0.7086211442947388, 0.7049204111099243}
|
||||
}; // 这里使用给定的旋转矩阵
|
||||
double[] minBounds = {-905.5771484375, 174.71572875976562, 69.14165496826172}; // 裁剪最小值
|
||||
double[] maxBounds = {321.80609130859375, 1170.4776611328125, 1199.3507080078125}; // 裁剪最大值
|
||||
|
||||
|
||||
private double floorHeight;
|
||||
|
||||
private double[] max_pt;
|
||||
private double[] min_pt;
|
||||
private double[] rotation;
|
||||
//路径D://config//3DConfig/"+相机sn+".json"
|
||||
private String configPath;
|
||||
//盘点路径 configProperties.getSavePath().getMediaPath() + street.getLeft3D()+ currentDate.format(formatter)+"/"+transmissionPojo.getCheckId()+".pcd";
|
||||
//随行路径 configProperties.getSavePath().getMediaPath() + street.getLeft3D()+"000/"+ currentDate.format(formatter)+"/"+transmissionPojo.getRow()+".pcd";
|
||||
private String pcd1;
|
||||
private String pcd2;
|
||||
|
||||
private String cameraSn1;
|
||||
private String cameraSn2;
|
||||
private Integer count;
|
||||
public PcdPojo setPCDInfo(PcdPojo pojo) throws IOException {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
// 读取 JSON 文件并转换为 配置信息
|
||||
PcdPojo pojoIn = mapper.readValue(new File(pojo.getConfigPath()), mapper.getTypeFactory().constructType(PcdPojo.class));
|
||||
|
||||
this.setMinBounds(pojoIn.getMin_pt());
|
||||
this.setMaxBounds(pojoIn.getMax_pt());
|
||||
double[] x = {pojoIn.getRotation()[0], pojoIn.getRotation()[1], pojoIn.getRotation()[2]};
|
||||
double[] y = {pojoIn.getRotation()[3], pojoIn.getRotation()[4], pojoIn.getRotation()[5]};
|
||||
double[] z = {pojoIn.getRotation()[6], pojoIn.getRotation()[7], pojoIn.getRotation()[8]};
|
||||
this.setRotationMatrix(new double[][]{x, y, z});
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue