2019-11-25 05:34:04 -05:00
|
|
|
package com.chameleonvision.vision.image;
|
|
|
|
|
|
2019-12-01 04:39:21 -05:00
|
|
|
import com.chameleonvision.vision.camera.CameraCapture;
|
|
|
|
|
import com.chameleonvision.vision.camera.USBCaptureProperties;
|
|
|
|
|
import edu.wpi.cscore.VideoMode;
|
2019-11-25 05:34:04 -05:00
|
|
|
import org.apache.commons.lang3.tuple.Pair;
|
|
|
|
|
import org.opencv.core.Mat;
|
|
|
|
|
import org.opencv.imgcodecs.Imgcodecs;
|
|
|
|
|
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
import java.nio.file.Path;
|
|
|
|
|
|
2019-12-01 04:39:21 -05:00
|
|
|
public class StaticImageCapture implements CameraCapture {
|
2019-11-25 05:34:04 -05:00
|
|
|
|
2019-12-01 04:39:21 -05:00
|
|
|
private Mat image = new Mat();
|
|
|
|
|
private final VideoMode fakeVideoMode;
|
|
|
|
|
private final com.chameleonvision.vision.image.CaptureProperties properties;
|
2019-11-25 05:34:04 -05:00
|
|
|
|
|
|
|
|
public StaticImageCapture(Path imagePath) {
|
2019-12-01 04:39:21 -05:00
|
|
|
this(imagePath, 70);
|
|
|
|
|
}
|
2019-11-25 05:34:04 -05:00
|
|
|
|
2019-12-01 04:39:21 -05:00
|
|
|
public StaticImageCapture(Path imagePath, double FOV) {
|
|
|
|
|
if (!Files.exists(imagePath)) throw new RuntimeException("Invalid path for image!");
|
2019-11-25 05:34:04 -05:00
|
|
|
|
2019-12-01 04:39:21 -05:00
|
|
|
Mat loadedImage = Imgcodecs.imread(imagePath.toString());
|
|
|
|
|
loadedImage.copyTo(image);
|
|
|
|
|
if (image.cols() > 0 && image.rows() > 0) {
|
|
|
|
|
fakeVideoMode = new VideoMode(VideoMode.PixelFormat.kBGR, image.cols(), image.rows(), 60);
|
|
|
|
|
} else {
|
|
|
|
|
throw new RuntimeException("Failed to load image!");
|
2019-11-25 05:34:04 -05:00
|
|
|
}
|
2019-12-01 04:39:21 -05:00
|
|
|
|
|
|
|
|
properties = new com.chameleonvision.vision.image.CaptureProperties(fakeVideoMode, FOV);
|
2019-11-25 05:34:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Pair<Mat, Long> getFrame() {
|
|
|
|
|
return Pair.of(image, System.nanoTime());
|
|
|
|
|
}
|
2019-12-01 04:39:21 -05:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public CaptureProperties getProperties() {
|
|
|
|
|
return properties;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public VideoMode getCurrentVideoMode() {
|
|
|
|
|
return fakeVideoMode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setExposure(int exposure) {
|
|
|
|
|
// do nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setBrightness(int brightness) {
|
|
|
|
|
// do nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setVideoMode(VideoMode mode) {
|
|
|
|
|
// do nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setVideoMode(int index) {
|
|
|
|
|
// do nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setGain(int gain) {
|
|
|
|
|
// do nothing
|
|
|
|
|
}
|
2019-11-25 05:34:04 -05:00
|
|
|
}
|