Skip to content

Commit

Permalink
playing around with native opencv, opengl/jogl
Browse files Browse the repository at this point in the history
  • Loading branch information
olir committed Mar 25, 2018
1 parent b42dacb commit 7b08eda
Show file tree
Hide file tree
Showing 23 changed files with 201 additions and 31 deletions.
21 changes: 21 additions & 0 deletions app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,27 @@
<version>0.1.1</version>
</dependency>
-->
<dependency>
<groupId>org.jogamp.gluegen</groupId>
<artifactId>gluegen-rt-main</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.jogamp.jogl</groupId>
<artifactId>jogl-all-main</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.jogamp.jocl</groupId>
<artifactId>jocl-main</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.jogamp.joal</groupId>
<artifactId>joal-main</artifactId>
<version>2.3.1</version>
</dependency>

</dependencies>

<profiles>
Expand Down
53 changes: 45 additions & 8 deletions app/src/main/java/de/screenflow/frankenstein/MovieProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.opencv.core.Mat;
Expand All @@ -27,6 +28,7 @@
import de.screenflow.frankenstein.task.Task;
import de.screenflow.frankenstein.task.TaskHandler;
import de.screenflow.frankenstein.task.TimeTaskHandler;
import de.screenflow.frankenstein.vf.FilterContext;
import de.screenflow.frankenstein.vf.FilterElement;
import de.screenflow.frankenstein.vf.SegmentVideoFilter;
import de.screenflow.frankenstein.vf.VideoFilter;
Expand Down Expand Up @@ -90,10 +92,17 @@ public void init(ProcessingListener l) {
}
}

FilterContext context = new FilterContext() {
HashMap<String,Object> valMap = new HashMap<String,Object>();
@Override
public Object getValue(String key) {
return valMap.get(key);
}
};
newFrame = frame;
for (VideoFilter filter : filters) {
System.out.println("MovieProcessor process " + filter.getClass().getName());
newFrame = filter.process(newFrame, 1);
newFrame = filter.process(newFrame, 1, context);
}
if (l != null)
l.nextFrameProcessed(newFrame, currentPos);
Expand Down Expand Up @@ -133,11 +142,18 @@ public void processStreamFrame(ProcessingListener l) {

frame = configuration.getSource().getFrame();
if (frame != null && !frame.empty()) {
FilterContext context = new FilterContext() {
HashMap<String,Object> valMap = new HashMap<String,Object>();
@Override
public Object getValue(String key) {
return valMap.get(key);
}
};
Mat newFrame = frame;
for (VideoFilter filter : filters) {
// System.out.println("MovieProcessor processStreamFrame " +
// filter.getClass().getName());
newFrame = filter.process(newFrame, currentPos);
newFrame = filter.process(newFrame, currentPos, context);
}
if (localFilters != null && !localFilters.isEmpty()) {
for (FilterElement element : localFilters) {
Expand All @@ -146,7 +162,7 @@ public void processStreamFrame(ProcessingListener l) {
// processStreamFrame
// " +
// element.filter);
newFrame = element.filter.process(newFrame, currentPos);
newFrame = element.filter.process(newFrame, currentPos, context);
}
}
}
Expand Down Expand Up @@ -214,24 +230,38 @@ public boolean process(ProcessingListener l) {
}
if (frame != null && !frame.empty()) {
if (!filters.isEmpty()) {
FilterContext context = new FilterContext() {
HashMap<String,Object> valMap = new HashMap<String,Object>();
@Override
public Object getValue(String key) {
return valMap.get(key);
}
};
newFrame = frame;
for (VideoFilter filter : filters) {
// System.out.println("MovieProcessor
// process"+filter.getClass().getName());
newFrame = filter.process(newFrame, i);
newFrame = filter.process(newFrame, i, context);
}
} else {
newFrame = frame;
}
if (localFilters != null && !localFilters.isEmpty()) {
FilterContext context = new FilterContext() {
HashMap<String,Object> valMap = new HashMap<String,Object>();
@Override
public Object getValue(String key) {
return valMap.get(key);
}
};
for (FilterElement element : localFilters) {
if (element.filter != null) {
if (element.r.start <= i && i < element.r.end) {
// System.out.println("MovieProcessor
// processStreamFrame
// " +
// element.filter);
newFrame = element.filter.process(newFrame, i);
newFrame = element.filter.process(newFrame, i, context);
}
}
}
Expand Down Expand Up @@ -441,26 +471,33 @@ public void seek(final ProcessingListener l, int frameId) {
currentPos = configuration.getSource().seek(frameId, l);
frame = configuration.getSource().getFrame();
if (frame != null && !frame.empty()) {
FilterContext context = new FilterContext() {
HashMap<String,Object> valMap = new HashMap<String,Object>();
@Override
public Object getValue(String key) {
return valMap.get(key);
}
};
Mat newFrame = frame;
for (VideoFilter filter : filters) {
// System.out.println("MovieProcessor process "+filter.getClass().getName());
newFrame = filter.process(newFrame, frameId);
newFrame = filter.process(newFrame, frameId, context);
}
if (localFilters != null && !localFilters.isEmpty()) {
for (FilterElement element : localFilters) {
if (element.filter != null) {
if (element.r.start <= currentPos && currentPos < element.r.end) {
// System.out.println("MovieProcessor processStreamFrame " +
// element.filter);
newFrame = element.filter.process(newFrame, currentPos);
newFrame = element.filter.process(newFrame, currentPos, context);
}
}
}
}
if (previewFilter!=null) {
// System.out.println("MovieProcessor processStreamFrame " +
// previewFilter);
newFrame = previewFilter.process(newFrame, currentPos);
newFrame = previewFilter.process(newFrame, currentPos, context);
}
if (l != null)
l.nextFrameProcessed(newFrame, currentPos);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package de.screenflow.frankenstein.vf;

public interface FilterContext {
Object getValue(String Key);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
import org.opencv.core.Mat;

public interface VideoFilter {
Mat process(Mat sourceFrame, int frameId);
Mat process(Mat sourceFrame, int frameId, FilterContext context);
Mat configure(Mat firstFrame);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.opencv.core.Size;
import org.opencv.imgproc.Imgproc;

import de.screenflow.frankenstein.vf.FilterContext;
import de.screenflow.frankenstein.vf.VideoFilter;

public class Anaglyph2LR implements VideoFilter {
Expand Down Expand Up @@ -63,7 +64,7 @@ public Mat configure(Mat sourceFrame) {
}

@Override
public Mat process(Mat sourceFrame, int frameId) {
public Mat process(Mat sourceFrame, int frameId, FilterContext context) {

List<Mat> sourcePlanes = new ArrayList<Mat>();
Core.split(sourceFrame, sourcePlanes); // planes[2] is the red channel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.opencv.core.Size;
import org.opencv.imgproc.Imgproc;

import de.screenflow.frankenstein.vf.FilterContext;
import de.screenflow.frankenstein.vf.VideoFilter;

public class CloneLR implements VideoFilter {
Expand All @@ -42,7 +43,7 @@ public Mat configure(Mat sourceFrame) {
}

@Override
public Mat process(Mat sourceFrame, int frameId) {
public Mat process(Mat sourceFrame, int frameId, FilterContext context) {
// System.out.println("???");

Rect roi = new Rect(0, 0, sourceFrame.cols(), sourceFrame.rows());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.opencv.core.Mat;
import org.opencv.core.Rect;

import de.screenflow.frankenstein.vf.FilterContext;
import de.screenflow.frankenstein.vf.VideoFilter;

public class LDelay implements VideoFilter {
Expand Down Expand Up @@ -50,7 +51,7 @@ public Mat configure(Mat sourceFrame) {
}

@Override
public Mat process(Mat sourceFrame, int frameId) {
public Mat process(Mat sourceFrame, int frameId, FilterContext context) {

int x1 = 0;
int x2 = sourceFrame.cols() >> 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.opencv.core.Size;
import org.opencv.imgproc.Imgproc;

import de.screenflow.frankenstein.vf.FilterContext;
import de.screenflow.frankenstein.vf.VideoFilter;

public class LR2VR180 implements VideoFilter {
Expand Down Expand Up @@ -130,7 +131,7 @@ public Mat configure(Mat sourceFrame) {
}

@Override
public Mat process(Mat sourceFrame, int frameId) {
public Mat process(Mat sourceFrame, int frameId, FilterContext context) {

Rect roiDest, roiSource;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.opencv.core.Size;
import org.opencv.imgproc.Imgproc;

import de.screenflow.frankenstein.vf.FilterContext;
import de.screenflow.frankenstein.vf.VideoFilter;

public class OU2LR implements VideoFilter {
Expand Down Expand Up @@ -60,7 +61,7 @@ public Mat configure(Mat sourceFrame) {
}

@Override
public Mat process(Mat sourceFrame, int frameId) {
public Mat process(Mat sourceFrame, int frameId, FilterContext context) {

Rect roi = new Rect(0, 0, smallWidth, smallHeight);
sourceFrame.submat(new Rect(0, 0, sourceFrame.cols(), sourceFrame.rows() >> 1)).copyTo(upperFrame);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.opencv.core.Size;
import org.opencv.imgproc.Imgproc;

import de.screenflow.frankenstein.vf.FilterContext;
import de.screenflow.frankenstein.vf.VideoFilter;

public class OutputSizeLimiter implements VideoFilter {
Expand Down Expand Up @@ -49,7 +50,7 @@ public Mat configure(Mat sourceFrame) {
}

@Override
public Mat process(Mat sourceFrame, int frameId) {
public Mat process(Mat sourceFrame, int frameId, FilterContext context) {

if (newFrame == null)
return sourceFrame;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.opencv.core.Mat;
import org.opencv.core.Rect;

import de.screenflow.frankenstein.vf.FilterContext;
import de.screenflow.frankenstein.vf.VideoFilter;

public class RL2LR implements VideoFilter {
Expand All @@ -34,7 +35,7 @@ public Mat configure(Mat sourceFrame) {
}

@Override
public Mat process(Mat sourceFrame, int frameId) {
public Mat process(Mat sourceFrame, int frameId, FilterContext context) {

Rect roi = new Rect(0, 0, sourceFrame.cols() >> 1, sourceFrame.rows());
sourceFrame.submat(new Rect(sourceFrame.cols() >> 1, 0, sourceFrame.cols() >> 1, sourceFrame.rows()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.opencv.imgproc.Imgproc;

import de.screenflow.frankenstein.ProcessingListener;
import de.screenflow.frankenstein.vf.FilterContext;
import de.screenflow.frankenstein.vf.VideoFilter;
import de.screenflow.frankenstein.vf.VideoSource;

Expand Down Expand Up @@ -67,7 +68,7 @@ public Mat configure(Mat sourceFrame) {
}

@Override
public Mat process(Mat sourceFrame, int frameId) {
public Mat process(Mat sourceFrame, int frameId, FilterContext context) {
int sid = (frameId - 1) / (fps * fpSlide);

if (sid < slides.size()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.opencv.imgproc.Imgproc;

import de.screenflow.frankenstein.ProcessingListener;
import de.screenflow.frankenstein.vf.FilterContext;
import de.screenflow.frankenstein.vf.VideoFilter;
import de.screenflow.frankenstein.vf.VideoSource;

Expand Down Expand Up @@ -60,7 +61,7 @@ public Mat configure(Mat sourceFrame) {
}

@Override
public Mat process(Mat sourceFrame, int frameId) {
public Mat process(Mat sourceFrame, int frameId, FilterContext context) {
testFrame.copyTo(newFrame);
System.out.println("process Frame #" + frameId);
Imgproc.putText(newFrame, "Frame #" + frameId, new Point(10, smallHeight - 10), Core.FONT_HERSHEY_PLAIN, 3.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.opencv.core.Mat;
import org.opencv.imgproc.Imgproc;

import de.screenflow.frankenstein.vf.FilterContext;

public class BWFilter extends DefaultSegmentFilter {

Mat grayFrame;
Expand All @@ -27,7 +29,7 @@ public BWFilter() {
}

@Override
public Mat process(Mat sourceFrame, int frameId) {
public Mat process(Mat sourceFrame, int frameId, FilterContext context) {
if (grayFrame == null || grayFrame.cols() != sourceFrame.cols() || grayFrame.rows() != sourceFrame.rows()) {
grayFrame = sourceFrame.clone();
}
Expand Down

0 comments on commit 7b08eda

Please sign in to comment.