4 changed files with 212 additions and 14 deletions
-
5pom.xml
-
24src/main/java/com/iflytop/digester/StartResetTaskThread.java
-
129src/main/java/com/iflytop/digester/camera/DiComBaslerCamera.java
-
68src/main/java/com/iflytop/digester/deviceinstance/Camera.java
@ -0,0 +1,129 @@ |
|||
package com.iflytop.digester.camera; |
|||
public class DiComBaslerCamera { |
|||
public static final int ACCESS_MODE_MONITOR = 0; |
|||
public static final int ACCESS_MODE_CONTROL = 1; |
|||
public static final int ACCESS_MODE_STREAM = (1 << 1); |
|||
public static final int ACCESS_MODE_EVENT = (1 << 2); |
|||
public static final int ACCESS_MODE_EXCLUSIVE = (1 << 3); |
|||
|
|||
public static class GrabResult { |
|||
public byte[] imageBuffer; |
|||
public int payloadType; |
|||
public int pixelType; |
|||
public int sizeX; |
|||
public int sizeY; |
|||
public int offsetX; |
|||
public int offsetY; |
|||
public int paddingX; |
|||
public int paddingY; |
|||
public long PayloadSize; |
|||
public int ErrorCode; |
|||
} |
|||
|
|||
/** |
|||
* Initializes the pylon runtime system. |
|||
*/ |
|||
public native void initialize(); |
|||
|
|||
/** |
|||
* Enumerates all camera devices. |
|||
* @return The number of found devices. |
|||
*/ |
|||
public native int enumerateDevices(); |
|||
|
|||
/** |
|||
* Terminates the pylon runtime system. |
|||
*/ |
|||
public native void terminate(); |
|||
|
|||
/** |
|||
* Creates a camera device by index. |
|||
* @param index The index of the camera device. |
|||
* @return The handle of the camera device. |
|||
*/ |
|||
public native long createDeviceByIndex(int index); |
|||
|
|||
/** |
|||
* Opens the camera device. |
|||
* @param hDev The handle of the camera device. |
|||
* @param accessMode The access mode. |
|||
*/ |
|||
public native void deviceOpen(long hDev, int accessMode); |
|||
|
|||
/** |
|||
* Checks if a camera device feature is readable. |
|||
* @param hDev The handle of the camera device. |
|||
* @param name The name of the feature. |
|||
* @return true if the feature is readable, false otherwise. |
|||
*/ |
|||
public native boolean deviceFeatureIsReadable(long hDev, String name); |
|||
|
|||
/** |
|||
* Read a camera device feature to a string. |
|||
* @param hDev The handle of the camera device. |
|||
* @param name The name of the feature. |
|||
* @param size The size of the string buffer. |
|||
* @return The string value of the feature. |
|||
*/ |
|||
public native String deviceFeatureToString(long hDev, String name, int size); |
|||
|
|||
/** |
|||
* Checks if a camera device feature is available. |
|||
* @param hDev The handle of the camera device. |
|||
* @param name The name of the feature. |
|||
* @return true if the feature is available, false otherwise. |
|||
*/ |
|||
public native boolean deviceFeatureIsAvailable(long hDev, String name); |
|||
|
|||
/** |
|||
* Writes a camera device feature from a string. |
|||
* @param hDev The handle of the camera device. |
|||
* @param name The name of the feature. |
|||
* @param value The value of the feature. |
|||
*/ |
|||
public native void deviceFeatureFromString(long hDev, String name, String value); |
|||
|
|||
/** |
|||
* Checks if a camera device feature is writable. |
|||
* @param hDev The handle of the camera device. |
|||
* @param name The name of the feature. |
|||
* @return true if the feature is writable, false otherwise. |
|||
*/ |
|||
public native boolean deviceFeatureIsWritable(long hDev, String name); |
|||
|
|||
/** |
|||
* Writes a camera device feature from an integer. |
|||
* @param hDev The handle of the camera device. |
|||
* @param name The name of the feature. |
|||
* @param value The value of the feature. |
|||
*/ |
|||
public native void deviceSetIntegerFeature(long hDev, String name, int value); |
|||
|
|||
/** |
|||
* Reads a camera device feature to an integer. |
|||
* @param hDev The handle of the camera device. |
|||
* @param name The name of the feature. |
|||
* @return The integer value of the feature. |
|||
*/ |
|||
public native int deviceGetIntegerFeatureInt32(long hDev, String name); |
|||
|
|||
/** |
|||
* Grabs a single frame from the camera device. |
|||
* @param hDev The handle of the camera device. |
|||
* @param channel The channel index. |
|||
* @return The grab result. |
|||
*/ |
|||
public native GrabResult deviceGrabSingleFrame(long hDev, int channel); |
|||
|
|||
/** |
|||
* Closes the camera device. |
|||
* @param hDev The handle of the camera device. |
|||
*/ |
|||
public native void deviceClose(long hDev); |
|||
|
|||
/** |
|||
* Destroys the camera device. |
|||
* @param hDev The handle of the camera device. |
|||
*/ |
|||
public native void destroyDevice(long hDev); |
|||
} |
@ -1,6 +1,74 @@ |
|||
package com.iflytop.digester.deviceinstance; |
|||
import com.iflytop.digester.camera.DiComBaslerCamera; |
|||
import org.springframework.stereotype.Component; |
|||
import org.opencv.core.CvType; |
|||
import org.opencv.core.Mat; |
|||
@Component |
|||
public class Camera { |
|||
// camera |
|||
private static DiComBaslerCamera pylon = null; |
|||
// index |
|||
protected Integer index; |
|||
// channel |
|||
protected Integer channel; |
|||
// camera handle |
|||
private long cam = -1; |
|||
|
|||
// get pylon |
|||
private DiComBaslerCamera getPylon() { |
|||
if ( null == Camera.pylon ) { |
|||
Camera.pylon = new DiComBaslerCamera(); |
|||
Camera.pylon.initialize(); |
|||
} |
|||
return Camera.pylon; |
|||
} |
|||
|
|||
// enable |
|||
public void enable( ) { |
|||
if ( -1 != this.cam ) { |
|||
return ; |
|||
} |
|||
|
|||
var pylon = this.getPylon(); |
|||
int count = pylon.enumerateDevices(); |
|||
if ( this.index >= count ) { |
|||
throw new RuntimeException("Camera index out of range"); |
|||
} |
|||
|
|||
this.cam = pylon.createDeviceByIndex(this.index); |
|||
pylon.deviceOpen(this.cam, DiComBaslerCamera.ACCESS_MODE_CONTROL | DiComBaslerCamera.ACCESS_MODE_STREAM); |
|||
|
|||
boolean isFeatureReadable = pylon.deviceFeatureIsReadable(cam, "DeviceModelName"); |
|||
if ( isFeatureReadable ) { |
|||
String name = pylon.deviceFeatureToString(cam, "DeviceModelName", 256); |
|||
} |
|||
|
|||
pylon.deviceFeatureFromString(cam, "PixelFormat", "Mono8"); |
|||
pylon.deviceFeatureFromString(cam, "TriggerSelector", "AcquisitionStart"); |
|||
pylon.deviceFeatureFromString(cam, "TriggerMode", "Off"); |
|||
pylon.deviceFeatureFromString(cam, "TriggerSelector", "FrameStart"); |
|||
pylon.deviceFeatureFromString(cam, "TriggerMode", "Off"); |
|||
pylon.deviceSetIntegerFeature(cam, "GevSCPSPacketSize", 1500); |
|||
pylon.deviceFeatureFromString(cam, "ExposureAuto", "Off"); |
|||
pylon.deviceSetIntegerFeature(cam, "ExposureTimeRaw", 27218); |
|||
} |
|||
|
|||
// disable |
|||
public void disable() { |
|||
if ( -1 == this.cam ) { |
|||
return ; |
|||
} |
|||
var pylon = this.getPylon(); |
|||
pylon.deviceClose(this.cam); |
|||
this.cam = -1; |
|||
} |
|||
|
|||
// grab |
|||
public Mat grabToMat () { |
|||
var pylon = this.getPylon(); |
|||
var result = pylon.deviceGrabSingleFrame(this.cam, this.channel); |
|||
Mat frameMat = new Mat(result.sizeY, result.sizeX, CvType.CV_8UC1); |
|||
frameMat.put(0, 0, result.imageBuffer); |
|||
return frameMat; |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue