1 changed files with 78 additions and 0 deletions
@ -0,0 +1,78 @@ |
|||||
|
package com.my.graphiteDigesterBg.diframe.actuator; |
||||
|
import com.my.graphiteDigesterBg.diframe.DiActuatorBase; |
||||
|
import com.my.graphiteDigesterBg.diframe.DiCommand; |
||||
|
import com.my.graphiteDigesterBg.diframe.component.baslerCamera.DiComBaslerCamera; |
||||
|
import org.opencv.core.CvType; |
||||
|
import org.opencv.core.Mat; |
||||
|
public class DiActCameraBasler extends DiActuatorBase { |
||||
|
// camera |
||||
|
private static DiComBaslerCamera pylon = null; |
||||
|
// index |
||||
|
protected Integer index; |
||||
|
// channel |
||||
|
protected Integer channel; |
||||
|
// camera handle |
||||
|
private long cam = 0; |
||||
|
|
||||
|
// get pylon |
||||
|
private DiComBaslerCamera getPylon() { |
||||
|
if ( null == DiActCameraBasler.pylon ) { |
||||
|
DiActCameraBasler.pylon = new DiComBaslerCamera(); |
||||
|
DiActCameraBasler.pylon.initialize(); |
||||
|
} |
||||
|
return DiActCameraBasler.pylon; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void setEnable( Boolean enable ) { |
||||
|
if ( enable ) { |
||||
|
this.onEnable(); |
||||
|
} else { |
||||
|
this.onDisable(); |
||||
|
} |
||||
|
this.log("setEnable({})", enable); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
protected void onEnable() { |
||||
|
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); |
||||
|
this.log("DeviceModelName : {}", name); |
||||
|
} |
||||
|
|
||||
|
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); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
protected void onDisable() { |
||||
|
var pylon = this.getPylon(); |
||||
|
pylon.deviceClose(this.cam); |
||||
|
// pylon.destroyDevice(this.cam); |
||||
|
} |
||||
|
|
||||
|
// 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