parent
29b826657c
commit
ec77871c28
@ -0,0 +1,165 @@
|
||||
package com.zhehekeji.web.controller;
|
||||
|
||||
import com.zhehekeji.core.pojo.Result;
|
||||
import com.zhehekeji.web.config.ConfigProperties;
|
||||
import com.zhehekeji.web.entity.Street;
|
||||
import com.zhehekeji.web.pojo.IndustrialCameraVO;
|
||||
import com.zhehekeji.web.pojo.stock.CheckLogSearch;
|
||||
import com.zhehekeji.web.service.IndustrialCamera.HikSaveImage;
|
||||
import com.zhehekeji.web.service.IndustrialCamera.LxPointCloudSaveImage;
|
||||
import com.zhehekeji.web.service.PlcService;
|
||||
import com.zhehekeji.web.service.StreetService;
|
||||
import com.zhehekeji.web.service.algorithm.FeatureMatchingExample;
|
||||
import com.zhehekeji.web.service.algorithm.InventoryService;
|
||||
import com.zhehekeji.web.service.algorithm.PcdPojo;
|
||||
import com.zhehekeji.web.service.algorithm.PointCloudProcessor;
|
||||
import com.zhehekeji.web.service.client.TransmissionPojo;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.imgcodecs.Imgcodecs;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.zhehekeji.web.service.algorithm.FeatureMatchingExample.base642Mat;
|
||||
|
||||
@Slf4j
|
||||
@Api(tags = "工业相机")
|
||||
@RequestMapping("/industrialCamera")
|
||||
@RestController
|
||||
public class IndustrialCameraController {
|
||||
@Resource
|
||||
HikSaveImage hikSaveImage;
|
||||
|
||||
@Resource
|
||||
StreetService streetService;
|
||||
@Resource
|
||||
PlcService plcService;
|
||||
|
||||
|
||||
@Resource
|
||||
ConfigProperties configProperties;
|
||||
|
||||
@ApiOperation("拍照")
|
||||
@PostMapping("pic")
|
||||
public Result<String> pic(@RequestBody CheckLogSearch checkLogSearch){
|
||||
Street street = streetService.streetById(checkLogSearch.getStreetId());
|
||||
if(configProperties.getCameraConfig().getIndustrialCamera()!=null) {
|
||||
String path = "industrialCamera/" + UUID.randomUUID() + ".jpeg";
|
||||
hikSaveImage.saveImage(configProperties.getCameraConfig().getIndustrialCamera(), configProperties.getSavePath().getMediaPath() + path, "sn");
|
||||
return new Result<>(path);
|
||||
}else {
|
||||
return new Result<>("");
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation("识别")
|
||||
@PostMapping("Macth")
|
||||
public Result<String> Macth(@RequestBody IndustrialCameraVO industrialCameraVo){
|
||||
String srcImg = configProperties.getSavePath().getMediaPath() + industrialCameraVo.getPicImg();
|
||||
String srcImgRest = configProperties.getSavePath().getMediaPath() + industrialCameraVo.getPicImg();
|
||||
//识别结果
|
||||
boolean re = FeatureMatchingExample.matchTemplate(
|
||||
InventoryService.readImagesInFolder(configProperties.getSavePath().getMediaPath() + "template/" + industrialCameraVo.getTypeMacth()),
|
||||
srcImg);
|
||||
if (re){
|
||||
|
||||
return new Result<>(industrialCameraVo.getPicImg()+".jpg");
|
||||
}else {
|
||||
|
||||
return new Result<>("");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("识别3D")
|
||||
@PostMapping("Macth3D")
|
||||
public Result<Integer> Macth3D(@RequestBody IndustrialCameraVO industrialCameraVo){
|
||||
LocalDate currentDate = LocalDate.now();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
//路径
|
||||
String pathPcd = configProperties.getSavePath().getMediaPath()
|
||||
+"camera3D/"
|
||||
+currentDate.format(formatter)+"/" +UUID.randomUUID()+"-";
|
||||
Integer count = inventoryService.match3D(industrialCameraVo.getName(),pathPcd+"-"+configProperties.getCameraConfig().getCamera3D()+".pcd");
|
||||
return Result.success(count);
|
||||
}
|
||||
|
||||
@Resource
|
||||
InventoryService inventoryService;
|
||||
//
|
||||
// @ApiOperation("匹配所有")
|
||||
// @PostMapping("matchFeatures")
|
||||
// public Boolean matchFeatures(@RequestBody TransmissionPojo transmissionPojo) {
|
||||
// //return true;
|
||||
//
|
||||
// return null;
|
||||
// }
|
||||
|
||||
//
|
||||
// @ApiOperation("随行")
|
||||
// @PostMapping("actionType")
|
||||
// public void action(@RequestBody TransmissionPojo transmissionPojo) {
|
||||
//
|
||||
// Street street = streetService.getStreetByPlcId(transmissionPojo.getStreetNumber());
|
||||
//
|
||||
//
|
||||
// //随行地址
|
||||
// String pcdPath1 =configProperties.getSavePath().getMediaPath() + street.getLeft3D()+"\\000\\"
|
||||
// +transmissionPojo.getRow()+"-"+transmissionPojo.getColumn()+"-"+transmissionPojo.getDirection()+"-L"+".pcd";
|
||||
//
|
||||
// String pcdPath2 =configProperties.getSavePath().getMediaPath() + street.getRight3D()+"\\000\\"
|
||||
// +transmissionPojo.getRow()+"-"+transmissionPojo.getColumn()+"-"+transmissionPojo.getDirection()+"-R"+".pcd";
|
||||
// //拍照
|
||||
// System.out.println(street.getLeft3D()+" 111211 "+ pcdPath1);
|
||||
// LxPointCloudSaveImage lxPointCloudSaveImage = new LxPointCloudSaveImage();
|
||||
// lxPointCloudSaveImage.saveImage(street.getLeft3D(), pcdPath1,1);
|
||||
//
|
||||
// LxPointCloudSaveImage lxPointCloudSaveImage1 = new LxPointCloudSaveImage();
|
||||
// lxPointCloudSaveImage1.saveImage(street.getRight3D(), pcdPath2,2);
|
||||
// }
|
||||
// @ApiOperation("模板建立")
|
||||
// @PostMapping("MacthCreate")
|
||||
// public Result<Boolean> MacthCreate(@RequestBody IndustrialCameraVO industrialCameraVo){
|
||||
// Path folder = Paths.get(configProperties.getSavePath().getMediaPath()+"template/"+industrialCameraVo.getTypeMacth());
|
||||
// try {
|
||||
// Files.walkFileTree(folder, new SimpleFileVisitor<Path>() {
|
||||
// @Override
|
||||
// public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
// Files.delete(file);
|
||||
// return FileVisitResult.CONTINUE;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
|
||||
// Files.delete(dir);
|
||||
// return FileVisitResult.CONTINUE;
|
||||
// }
|
||||
// });
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// for (int i = 0; i < industrialCameraVo.getFileList().size(); i++){
|
||||
// try {
|
||||
// Mat template = base642Mat(industrialCameraVo.getFileList().get(i).getThumbUrl()
|
||||
// .replace("data:image/jpeg;base64,","").replace("data:image/png;base64,",""));
|
||||
//
|
||||
// Imgcodecs.imwrite(configProperties.getSavePath().getMediaPath()+"template/"+industrialCameraVo.getTypeMacth()+"/"+i+".jpg", template);
|
||||
// } catch (IOException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// }
|
||||
// return new Result<>(true);
|
||||
// }
|
||||
}
|
||||
@ -1,11 +1,45 @@
|
||||
package com.zhehekeji.web.controller;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.zhehekeji.core.pojo.Result;
|
||||
import com.zhehekeji.web.entity.KuKou;
|
||||
import com.zhehekeji.web.pojo.OrderSearch;
|
||||
import com.zhehekeji.web.pojo.OrderVO;
|
||||
import com.zhehekeji.web.service.KuKouService;
|
||||
import com.zhehekeji.web.service.OrderService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Api(tags = "盘点统计")
|
||||
@RequestMapping("/KuKouController")
|
||||
@RestController
|
||||
public class KuKouController {
|
||||
@Resource
|
||||
private KuKouService kuKouService;
|
||||
@Resource
|
||||
private OrderService orderService;
|
||||
|
||||
|
||||
@PostMapping("/list")
|
||||
@ApiOperation(value = "查询")
|
||||
//@SessionHandler
|
||||
public Result<PageInfo<KuKou>> list(@RequestBody OrderSearch orderSearch) {
|
||||
//validatorUtil.validate(orderSearch);
|
||||
return Result.success(kuKouService.pageInfo(orderSearch));
|
||||
}
|
||||
|
||||
@PostMapping("/latest")
|
||||
@ApiOperation(value = "最新数据")
|
||||
//@SessionHandler
|
||||
public Result<KuKou> latest() {
|
||||
//validatorUtil.validate(orderSearch);
|
||||
return Result.success(kuKouService.latest());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
package com.zhehekeji.web.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.zhehekeji.web.entity.EmptyCheckPic;
|
||||
import com.zhehekeji.web.entity.KuKou;
|
||||
|
||||
public interface KukouMapper extends BaseMapper<KuKou> {
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
package com.zhehekeji.web.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class IndustrialCameraVO {
|
||||
private String name;
|
||||
private String picImg;
|
||||
private String typeMacth;
|
||||
//private List<ImgFile> fileList;
|
||||
private String pcdPath;
|
||||
|
||||
|
||||
private String streetId;
|
||||
}
|
||||
@ -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,321 @@
|
||||
package com.zhehekeji.web.service.IndustrialCamera; /***************************************************************************************************
|
||||
* @file SaveImage.java
|
||||
* @breif Use functions provided in MvCameraControlWrapper.jar to save image as JPEG。
|
||||
* @author zhanglei72
|
||||
* @date 2020/02/10
|
||||
*
|
||||
* @warning
|
||||
* @version V1.0.0 2020/02/10 Create this file
|
||||
* @since 2020/02/10
|
||||
**************************************************************************************************/
|
||||
|
||||
import MvCameraControlWrapper.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PreDestroy;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static MvCameraControlWrapper.MvCameraControl.*;
|
||||
import static MvCameraControlWrapper.MvCameraControlDefines.*;
|
||||
|
||||
@Service
|
||||
public class HikSaveImage implements CameraSaveUtil{
|
||||
|
||||
// 设备句柄保存
|
||||
static Map<String,Handle> handleMap = new ConcurrentHashMap<>();
|
||||
private static void printDeviceInfo(MV_CC_DEVICE_INFO stDeviceInfo)
|
||||
{
|
||||
if (null == stDeviceInfo) {
|
||||
System.out.println("stDeviceInfo is null");
|
||||
return;
|
||||
}
|
||||
|
||||
if (stDeviceInfo.transportLayerType == MV_GIGE_DEVICE) {
|
||||
System.out.println("\tCurrentIp: " + stDeviceInfo.gigEInfo.currentIp);
|
||||
System.out.println("\tserialNumber: " + stDeviceInfo.gigEInfo.serialNumber);
|
||||
System.out.println("\tModel: " + stDeviceInfo.gigEInfo.modelName);
|
||||
System.out.println("\tUserDefinedName: " + stDeviceInfo.gigEInfo.userDefinedName);
|
||||
} else if (stDeviceInfo.transportLayerType == MV_USB_DEVICE) {
|
||||
System.out.println("\tUserDefinedName: " + stDeviceInfo.usb3VInfo.userDefinedName);
|
||||
System.out.println("\tSerial Number: " + stDeviceInfo.usb3VInfo.serialNumber);
|
||||
System.out.println("\tDevice Number: " + stDeviceInfo.usb3VInfo.deviceNumber);
|
||||
} else {
|
||||
System.err.print("Device is not supported! \n");
|
||||
}
|
||||
|
||||
System.out.println("\tAccessible: "
|
||||
+ MvCameraControl.MV_CC_IsDeviceAccessible(stDeviceInfo, MV_ACCESS_Exclusive));
|
||||
System.out.println("");
|
||||
}
|
||||
|
||||
private static void printFrameInfo(MV_FRAME_OUT_INFO stFrameInfo)
|
||||
{
|
||||
if (null == stFrameInfo)
|
||||
{
|
||||
System.err.println("stFrameInfo is null");
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuilder frameInfo = new StringBuilder("");
|
||||
frameInfo.append(("\tFrameNum[" + stFrameInfo.frameNum + "]"));
|
||||
frameInfo.append("\tWidth[" + stFrameInfo.width + "]");
|
||||
frameInfo.append("\tHeight[" + stFrameInfo.height + "]");
|
||||
frameInfo.append(String.format("\tPixelType[%#x]", stFrameInfo.pixelType.getnValue()));
|
||||
|
||||
System.out.println(frameInfo.toString());
|
||||
}
|
||||
|
||||
public static void saveDataToFile(byte[] dataToSave, int dataSize, String fileName)
|
||||
{
|
||||
OutputStream os = null;
|
||||
|
||||
try
|
||||
{
|
||||
Path path = Paths.get(fileName);
|
||||
|
||||
// 检查文件是否存在
|
||||
if (!Files.exists(path)) {
|
||||
try {
|
||||
// 创建所有父目录
|
||||
Files.createDirectories(path.getParent());
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
System.err.println("Failed to create file: " + e.getMessage());
|
||||
}
|
||||
} else {
|
||||
System.out.println("File already exists: " + path);
|
||||
}
|
||||
// 创建文件
|
||||
|
||||
os = new FileOutputStream( fileName);
|
||||
os.write(dataToSave, 0, dataSize);
|
||||
System.out.println("SaveImage succeed.");
|
||||
// Create directory
|
||||
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Close file stream
|
||||
try
|
||||
{
|
||||
os.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static int chooseCamera(ArrayList<MV_CC_DEVICE_INFO> stDeviceList,String sn ,String type)
|
||||
{
|
||||
if (null == stDeviceList)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
for(int i = 0; i < stDeviceList.size(); i++){
|
||||
if(type.equals("sn") && sn.equals(stDeviceList.get(i).gigEInfo.serialNumber)){
|
||||
|
||||
return i;
|
||||
}else if(type.equals("ip") && sn.equals(stDeviceList.get(i).gigEInfo.currentIp)){
|
||||
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
HikSaveImage hikSaveImage = new HikSaveImage();
|
||||
hikSaveImage.saveImage("00J51775660", "E:\\m\\55.bpm","sn");
|
||||
}
|
||||
@PreDestroy
|
||||
void clean(){
|
||||
for (Handle h :handleMap.values()){
|
||||
|
||||
// Stop grabbing
|
||||
int nRet = MvCameraControl.MV_CC_StopGrabbing(h);
|
||||
if (MV_OK != nRet)
|
||||
{
|
||||
System.err.printf("StopGrabbing fail, errcode: [%#x]\n", nRet);
|
||||
break;
|
||||
}
|
||||
nRet = MvCameraControl.MV_CC_DestroyHandle(h);
|
||||
if (MV_OK != nRet) {
|
||||
System.err.printf("DestroyHandle failed, errcode: [%#x]\n", nRet);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public boolean saveImage(String sn, String path,String type) {
|
||||
int nRet = MV_OK;
|
||||
ArrayList<MV_CC_DEVICE_INFO> stDeviceList;
|
||||
|
||||
do
|
||||
{
|
||||
System.out.println("SDK Version " + MvCameraControl.MV_CC_GetSDKVersion());
|
||||
|
||||
// Enuerate GigE and USB devices
|
||||
try
|
||||
{
|
||||
stDeviceList = MV_CC_EnumDevices(MV_GIGE_DEVICE | MV_USB_DEVICE);
|
||||
if (0 >= stDeviceList.size())
|
||||
{
|
||||
System.out.println("No devices found!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (CameraControlException e)
|
||||
{
|
||||
System.err.println("Enumrate devices failed!" + e.toString());
|
||||
e.printStackTrace();
|
||||
break;
|
||||
}
|
||||
|
||||
// choose camera
|
||||
|
||||
|
||||
Handle hCamera = init(sn,stDeviceList,type);
|
||||
// Create handle
|
||||
|
||||
|
||||
|
||||
// Get payload size
|
||||
MVCC_INTVALUE stParam = new MVCC_INTVALUE();
|
||||
nRet = MvCameraControl.MV_CC_GetIntValue(hCamera, "PayloadSize", stParam);
|
||||
if (MV_OK != nRet)
|
||||
{
|
||||
System.err.printf("Get PayloadSize fail, errcode: [%#x]\n", nRet);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Get one frame
|
||||
MV_FRAME_OUT_INFO stImageInfo = new MV_FRAME_OUT_INFO();
|
||||
byte[] pData = new byte[(int)stParam.curValue];
|
||||
nRet = MvCameraControl.MV_CC_GetOneFrameTimeout(hCamera, pData, stImageInfo, 1000);
|
||||
while(true){
|
||||
if(stImageInfo.height >0 && stImageInfo.width >0){
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (MV_OK != nRet)
|
||||
{
|
||||
System.err.printf("GetOneFrameTimeout fail, errcode:[%#x]\n", nRet);
|
||||
break;
|
||||
}
|
||||
|
||||
System.out.println("GetOneFrame: ");
|
||||
printFrameInfo(stImageInfo);
|
||||
int imageLen = stImageInfo.width * stImageInfo.height * 3; // Every RGB pixel takes 3 bytes
|
||||
byte[] imageBuffer = new byte[imageLen];
|
||||
|
||||
// Call MV_CC_SaveImage to save image as JPEG
|
||||
MV_SAVE_IMAGE_PARAM stSaveParam = new MV_SAVE_IMAGE_PARAM();
|
||||
stSaveParam.width = stImageInfo.width; // image width
|
||||
stSaveParam.height = stImageInfo.height; // image height
|
||||
stSaveParam.data = pData; // image data
|
||||
stSaveParam.dataLen = stImageInfo.frameLen; // image data length
|
||||
stSaveParam.pixelType = stImageInfo.pixelType; // image pixel format
|
||||
stSaveParam.imageBuffer = imageBuffer; // output image buffer
|
||||
stSaveParam.imageType = MV_SAVE_IAMGE_TYPE.MV_Image_Jpeg; // output image pixel format
|
||||
stSaveParam.methodValue = 0; // Interpolation method that converts Bayer format to RGB24. 0-Neareast 1-double linear 2-Hamilton
|
||||
stSaveParam.jpgQuality = 99; // JPG endoding quality(50-99]
|
||||
|
||||
nRet = MvCameraControl.MV_CC_SaveImage(hCamera, stSaveParam);
|
||||
if (MV_OK != nRet)
|
||||
{
|
||||
System.err.printf("SaveImage fail, errcode: [%#x]\n", nRet);
|
||||
break;
|
||||
}
|
||||
|
||||
// Save buffer content to file
|
||||
saveDataToFile(imageBuffer, imageLen, path);
|
||||
|
||||
} while (false);
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
Handle init(String sn, ArrayList<MV_CC_DEVICE_INFO> stDeviceList,String type){
|
||||
int nRet = MV_OK;
|
||||
int camIndex = -1;
|
||||
|
||||
Handle hCamera = null;
|
||||
try
|
||||
{
|
||||
if(handleMap.containsKey(sn) && handleMap.get(sn)!=null){
|
||||
//已经获得句柄
|
||||
hCamera = handleMap.get(sn);
|
||||
}else {
|
||||
System.out.println("创建句柄");
|
||||
camIndex = chooseCamera(stDeviceList,sn,type);
|
||||
if (camIndex == -1)
|
||||
{
|
||||
System.out.println("未找到摄像头");
|
||||
return null;
|
||||
}
|
||||
//未获得句柄并初始化
|
||||
hCamera = MvCameraControl.MV_CC_CreateHandle(stDeviceList.get(camIndex));
|
||||
handleMap.put(sn,hCamera);
|
||||
|
||||
// Open device
|
||||
nRet = MvCameraControl.MV_CC_OpenDevice(hCamera);
|
||||
if (MV_OK != nRet)
|
||||
{
|
||||
System.err.printf("Connect to camera failed, errcode: [%#x]\n", nRet);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// Make sure that trigger mode is off
|
||||
nRet = MvCameraControl.MV_CC_SetEnumValueByString(hCamera, "TriggerMode", "Off");
|
||||
if (MV_OK != nRet)
|
||||
{
|
||||
System.err.printf("SetTriggerMode failed, errcode: [%#x]\n", nRet);
|
||||
|
||||
return null;
|
||||
}
|
||||
// Get payload size
|
||||
|
||||
|
||||
// Start grabbing
|
||||
nRet = MvCameraControl.MV_CC_StartGrabbing(hCamera);
|
||||
if (MV_OK != nRet)
|
||||
{
|
||||
System.err.printf("Start Grabbing fail, errcode: [%#x]\n", nRet);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (CameraControlException e)
|
||||
{
|
||||
System.err.println("Create handle failed!" + e.toString());
|
||||
e.printStackTrace();
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
System.out.println(hCamera);
|
||||
return hCamera;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,106 @@
|
||||
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\\LxCameraApi.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;
|
||||
INSTANCE = INSTANCER;
|
||||
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,32 @@
|
||||
package com.zhehekeji.web.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.zhehekeji.web.entity.KuKou;
|
||||
import com.zhehekeji.web.mapper.KukouMapper;
|
||||
import com.zhehekeji.web.pojo.OrderSearch;
|
||||
import com.zhehekeji.web.pojo.OrderVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class KuKouService extends ServiceImpl<KukouMapper,KuKou> implements IService<KuKou> {
|
||||
public PageInfo<KuKou> pageInfo(OrderSearch orderSearch){
|
||||
PageHelper.startPage(orderSearch.getPageNum(), orderSearch.getPageSize());
|
||||
List<KuKou> kuKous = list(new QueryWrapper<>());
|
||||
|
||||
return new PageInfo<>(kuKous);
|
||||
}
|
||||
|
||||
public KuKou latest(){
|
||||
KuKou kuKou = getOne(new QueryWrapper<KuKou>().orderByDesc("createTime").last("limit 1"));
|
||||
|
||||
return kuKou;
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@ -0,0 +1,77 @@
|
||||
package com.zhehekeji.web.service.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,42 @@
|
||||
package com.zhehekeji.web.service.algorithm;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@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;
|
||||
PcdPojo setPCDInfo(PcdPojo pojo) {
|
||||
this.setMinBounds(pojo.getMin_pt());
|
||||
this.setMaxBounds(pojo.getMax_pt());
|
||||
double[] x = {pojo.getRotation()[0], pojo.getRotation()[1], pojo.getRotation()[2]};
|
||||
double[] y = {pojo.getRotation()[3], pojo.getRotation()[4], pojo.getRotation()[5]};
|
||||
double[] z = {pojo.getRotation()[6], pojo.getRotation()[7], pojo.getRotation()[8]};
|
||||
this.setRotationMatrix(new double[][]{x, y, z});
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue