Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
supertick committed Oct 16, 2023
1 parent 84a0367 commit da541c4
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 8 deletions.
49 changes: 47 additions & 2 deletions src/main/java/org/myrobotlab/service/OpenCV.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
import javax.imageio.ImageIO;
import javax.imageio.stream.MemoryCacheImageOutputStream;

import org.bytedeco.ffmpeg.global.avcodec;
import org.bytedeco.javacpp.avutil;
import org.bytedeco.javacv.CanvasFrame;
import org.bytedeco.javacv.FFmpegFrameRecorder;
import org.bytedeco.javacv.Frame;
Expand Down Expand Up @@ -148,6 +150,8 @@ public class OpenCV extends AbstractComputerVision<OpenCVConfig> implements Imag
int vpId = 0;

transient CanvasFrame canvasFrame = null;

transient FFmpegFrameRecorder recorder = null;

class VideoProcessor implements Runnable {

Expand All @@ -168,6 +172,44 @@ synchronized public void run() {
lengthInTime = grabber.getLengthInTime();
log.info("grabber {} started - length time {} length frames {}", grabberType, lengthInTime, lengthInFrames);

// create recorder
recorder = new FFmpegFrameRecorder("output.flv", grabber.getImageWidth(), grabber.getImageHeight());
// recorder.setFormat("mp4");
recorder.setFormat("flv");

// recorder.setFormat("ogg"); // Set the output format to Ogg
// recorder.setVideoCodec(avcodec.AV_CODEC_ID_THEORA); // Set the video codec to Theora
// recorder.setPixelFormat(avutil.AV_PIX_FMT_YUV420P); // Set pixel format
//
// recorder.setVideoCodec(avcodec.AV_CODEC_ID_THEORA); // Set the video codec to Theora
// recorder.setPixelFormat(avutil.AV_PIX_FMT_YUV420P); // Set pixel format
// recorder.start();
//
// recorder.start();

// h264
// recorder.setFormat("mp4");
// recorder.setVideoQuality(10);
// recorder.setFrameRate(grabber1.getFrameRate());
// recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);




// webm
// recorder.setVideoCodecName("libvpx-vp9");
// recorder.setFormat("webm");
// recorder.setPixelFormat(org.bytedeco.javacv.Frame.DEPTH_UBYTE);
// recorder.setFrameRate(frameRate);


// not sure what this is .. but it works
// recorder.setFormat("ffm");


recorder.start();


// Wait for the Kinect to heat up.
int loops = 0;
while (grabber.getClass() == OpenKinectFrameGrabber.class && lengthInFrames == 0 && loops < 200) {
Expand Down Expand Up @@ -197,6 +239,8 @@ synchronized public void run() {
++frameIndex;

data = new OpenCVData(getName(), frameStartTs, frameIndex, newFrame);

recorder.record(newFrame);

if (grabber.getClass().equals(OpenKinectFrameGrabber.class)) {
// by default this framegrabber returns video
Expand Down Expand Up @@ -1214,6 +1258,7 @@ private void processVideo(OpenCVData data) throws org.bytedeco.javacv.FrameGrabb
BufferedImage b = data.getDisplay();
SerializableImage si = new SerializableImage(b, displayFilter, frameIndex);
invoke("publishDisplay", si);
// sleep(1000);

if (webViewer) {
// broadcast(???)
Expand Down Expand Up @@ -2085,8 +2130,8 @@ public static void main(String[] args) throws Exception {
// Runtime.start("python", "Python");
OpenCV cv = (OpenCV) Runtime.start("cv", "OpenCV");

OpenCVFilter fr = new OpenCVFilterFaceRecognizer("fr");
cv.addFilter(fr);
// OpenCVFilter fr = new OpenCVFilterFaceRecognizer("fr");
// cv.addFilter(fr);
// OpenCVFilterTracker tracker = new OpenCVFilterTracker("tracker");
// cv.addFilter(tracker);
// OpenCVFilterLKOpticalTrack lk = new OpenCVFilterLKOpticalTrack("lk");
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/org/myrobotlab/service/ServoMixer.java
Original file line number Diff line number Diff line change
Expand Up @@ -676,14 +676,24 @@ public void stopService() {
public static void main(String[] args) throws Exception {

try {
LoggingFactory.init("WARN");

WebGui webgui = (WebGui) Runtime.create("webgui", "WebGui");
webgui.autoStartBrowser(false);
webgui.startService();


boolean done = true;
if (done) {
return;
}


Runtime.main(new String[] { "--id", "admin"});
LoggingFactory.init("INFO");

Runtime.start("i01.head.rothead", "Servo");
Runtime.start("i01.head.neck", "Servo");
WebGui webgui = (WebGui) Runtime.create("webgui", "WebGui");
webgui.autoStartBrowser(false);
webgui.startService();
Python python = (Python) Runtime.start("python", "Python");
ServoMixer mixer = (ServoMixer) Runtime.start("mixer", "ServoMixer");
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,11 +536,11 @@ public Plan getDefault(Plan plan, String name) {
listeners.add(new Listener("publishPlayAudioFile", getPeerName("audioPlayer")));


// service --to--> service
// service --to--> service
ServoMixerConfig servoMixer = (ServoMixerConfig) plan.get(getPeerName("servoMixer"));
servoMixer.listeners = new ArrayList<>();
servoMixer.listeners.add(new Listener("publishText", name + ".mouth", "onText"));

servoMixer.listeners.add(new Listener("publishText", getPeerName("mouth"), "onText"));


// remove the auto-added starts in the plan's runtime RuntimConfig.registry
Expand Down

0 comments on commit da541c4

Please sign in to comment.