mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-19 00:41:41 +00:00
Ingest wpilib!7609 and add turbo button (#1662)
Now that https://github.com/wpilibsuite/allwpilib/pull/7572 and https://github.com/wpilibsuite/allwpilib/pull/7609 have been merged: - Adds a magic hidden button to enable the new frame grabber behavior by adding a boolean topic at `/photonvision/use_new_cscore_frametime`. Toggle this to true to maybe increase FPS at the cost of latency variability - Bumps WPILib to ingest https://github.com/wpilibsuite/allwpilib/pull/7609 , but doesn't currently provide any user feedback about the time source. I don't think that reporting this super matters? --------- Co-authored-by: Jade <spacey-sooty@proton.me>
This commit is contained in:
107
photon-targeting/src/test/java/jni/CscoreExtrasTest.java
Normal file
107
photon-targeting/src/test/java/jni/CscoreExtrasTest.java
Normal file
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright (C) Photon Vision.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package jni;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
import edu.wpi.first.cameraserver.CameraServer;
|
||||
import edu.wpi.first.cscore.CameraServerJNI;
|
||||
import edu.wpi.first.cscore.CvSink;
|
||||
import edu.wpi.first.cscore.CvSource;
|
||||
import edu.wpi.first.cscore.UsbCamera;
|
||||
import edu.wpi.first.hal.HAL;
|
||||
import edu.wpi.first.util.PixelFormat;
|
||||
import edu.wpi.first.util.RawFrame;
|
||||
import java.io.IOException;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.opencv.core.Mat;
|
||||
import org.photonvision.jni.CscoreExtras;
|
||||
import org.photonvision.jni.PhotonTargetingJniLoader;
|
||||
import org.photonvision.jni.WpilibLoader;
|
||||
|
||||
public class CscoreExtrasTest {
|
||||
@BeforeAll
|
||||
public static void load_wpilib() throws UnsatisfiedLinkError, IOException {
|
||||
if (!WpilibLoader.loadLibraries()) {
|
||||
fail();
|
||||
}
|
||||
if (!PhotonTargetingJniLoader.load()) {
|
||||
fail();
|
||||
}
|
||||
|
||||
HAL.initialize(1000, 0);
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void teardown() {
|
||||
HAL.shutdown();
|
||||
}
|
||||
|
||||
// Skip this test for now. This doesn't work in CI anyways.
|
||||
// @Test
|
||||
public void testCaptureImage() {
|
||||
assumeTrue(CameraServerJNI.enumerateUsbCameras().length > 0);
|
||||
|
||||
UsbCamera camera = CameraServer.startAutomaticCapture(2);
|
||||
|
||||
camera.setVideoMode(PixelFormat.kMJPEG, 1280, 720, 30);
|
||||
var cameraMode = camera.getVideoMode();
|
||||
|
||||
CvSink cvSink = CameraServer.getVideo(camera);
|
||||
|
||||
CvSource outputStream = CameraServer.putVideo("Detected", 640, 480);
|
||||
|
||||
long lastTime = 0;
|
||||
for (long i = 0; i < 10000000; i++) {
|
||||
var frame = new RawFrame();
|
||||
frame.setInfo(
|
||||
cameraMode.width,
|
||||
cameraMode.height,
|
||||
// hard-coded 3 channel
|
||||
cameraMode.width * 3,
|
||||
PixelFormat.kBGR);
|
||||
final double CSCORE_DEFAULT_FRAME_TIMEOUT = 1.0 / 4.0;
|
||||
long time =
|
||||
CscoreExtras.grabRawSinkFrameTimeoutLastTime(
|
||||
cvSink.getHandle(), frame.getNativeObj(), CSCORE_DEFAULT_FRAME_TIMEOUT, lastTime);
|
||||
|
||||
if (time != 0) {
|
||||
var mat = new Mat(CscoreExtras.wrapRawFrame(frame.getNativeObj()));
|
||||
|
||||
System.out.println(mat);
|
||||
System.out.println(
|
||||
"Mat is " + mat.cols() + " x " + mat.rows() + " (cols x rows) with type " + mat.type());
|
||||
|
||||
outputStream.putFrame(mat);
|
||||
|
||||
mat.release();
|
||||
} else {
|
||||
System.err.println("Sink produced an error...");
|
||||
}
|
||||
|
||||
lastTime = time;
|
||||
|
||||
frame.close();
|
||||
}
|
||||
|
||||
cvSink.close();
|
||||
camera.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user