Skip to content

Commit

Permalink
Started on native Video-Equalizer Filter
Browse files Browse the repository at this point in the history
  • Loading branch information
olir committed Mar 23, 2018
1 parent 06fa078 commit 7d421fe
Show file tree
Hide file tree
Showing 19 changed files with 144 additions and 812 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
**/.settings/
**/target/
**/velocity.log
**/*.log
**/Thumbs.db
**/*.dll
**/.externalToolBuilders/
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/de/screenflow/frankenstein/fxml/FxMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import de.screenflow.frankenstein.vf.segment.BWFilter;
import de.screenflow.frankenstein.vf.segment.NativeExampleFilter;
import de.screenflow.frankenstein.vf.segment.StereoDistanceFilter;
import de.screenflow.frankenstein.vf.segment.VideoEqualizerFilter;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
Expand Down Expand Up @@ -191,6 +192,7 @@ public void createSegmentFilters() {

try {
segmentFilters.add(new NativeExampleFilter()); // try to load from plugin jar
segmentFilters.add(new VideoEqualizerFilter()); // try to load from plugin jar
}
catch(Throwable t) {
t.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,16 @@ protected NativeSegmentFilter(String identifier, String proxyClassName) {

try {
// use dynamic loading and reflection when loading jni proxy class
// from jar, so app do
// not depend on it.
// from jar, so app do not depend on it.
URLClassLoader childLoader = getLoader();
jniProxyClass = Class.forName(proxyClassName, true, childLoader);
jniProxy = jniProxyClass.newInstance();
jniProxyInitMethod = jniProxyClass.getMethod("init");
jniProxyInitMethod.invoke(jniProxy);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException
| SecurityException | IllegalArgumentException | InvocationTargetException | MalformedURLException e) {
throw new RuntimeException("jni wrapper creation failed", e);
throw new RuntimeException("jni wrapper creation failed. Bug-Mining: Ensure the wrapper was added to the javahClassNames in pom.xml. Check NativeCode.h for existing and proper signatures.", e);
}

}

static synchronized URLClassLoader getLoader() throws MalformedURLException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package de.screenflow.frankenstein.vf.segment;

public class VideoEqualizerConfigController {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2017 Oliver Rode, https://github.com/olir/Frankenstein
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.screenflow.frankenstein.vf.segment;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.opencv.core.Mat;

public class VideoEqualizerFilter extends NativeSegmentFilter<VideoEqualizerConfigController> {

private final static String JNI_FILTER_CLASS = "de.screenflow.frankenstein.vf.jni.VideoEqualizer";

private final Method jniProxyProcessMethod;

@SuppressWarnings("unchecked")
public VideoEqualizerFilter() throws UnsatisfiedLinkError {
super("videoequalizer", JNI_FILTER_CLASS);
try {
jniProxyProcessMethod = getJniProxyClass().getMethod("process", Object.class, int.class);
} catch (NoSuchMethodException | SecurityException | IllegalArgumentException e) {
throw new RuntimeException("jni wrapper creation failed", e);
}
}

@Override
public Mat process(Mat sourceFrame, int frameId) {
try {
jniProxyProcessMethod.invoke(getJniProxy(), sourceFrame, frameId);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
}
return sourceFrame;
}

@Override
protected void initializeController() {
// getConfigController(). ...
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.BorderPane?>

<BorderPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.screenflow.frankenstein.vf.segment.VideoEqualizerConfigController">
</BorderPane>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name=Video-Equalizer
400 changes: 0 additions & 400 deletions app/src/main/resources/hs_err_pid15736.log

This file was deleted.

403 changes: 0 additions & 403 deletions app/src/main/resources/hs_err_pid6128.log

This file was deleted.

4 changes: 3 additions & 1 deletion jniplugin/java/src/main/java/cc0/JniExample.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package cc0;

import de.screenflow.frankenstein.vf.jni.NativeFilter;

public class JniExample {
public JniExample() throws UnsatisfiedLinkError {
NativeFilter.loadLibrary();
NativeFilter.loadLibrary();
}

public static void main(String[] args) {
Expand Down
2 changes: 2 additions & 0 deletions jniplugin/java/src/main/java/cc0/NativeExample.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package cc0;

import de.screenflow.frankenstein.vf.jni.NativeFilter;

public class NativeExample extends NativeFilter {
public NativeExample() throws UnsatisfiedLinkError {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cc0;
package de.screenflow.frankenstein.vf.jni;

import java.io.File;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package de.screenflow.frankenstein.vf.jni;

public class VideoEqualizer extends NativeFilter {
public VideoEqualizer() throws UnsatisfiedLinkError {
}

public native void init();
public native void process(Object mat, int frameId);
}
1 change: 1 addition & 0 deletions jniplugin/native/include/JwMat.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class JwMat // begin declaration of the class
int channels(JNIEnv* env, jobject matobj);
long dataAddr(JNIEnv* env, jobject matobj);
long step1(JNIEnv* env, jobject matobj);
static JwMat* matptr;
private: // begin private section
jclass clsMat;
jmethodID m_rows;
Expand Down
2 changes: 2 additions & 0 deletions jniplugin/native/src/main/native/JwMat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

using namespace std;

JwMat* JwMat::matptr = NULL;

JwMat::JwMat(JNIEnv* env)
{
cout << "JwMat() START" << endl;
Expand Down
6 changes: 3 additions & 3 deletions jniplugin/native/src/main/native/NativeExample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
using namespace std;
using namespace cv;

JwMat* mat;

JNIEXPORT void JNICALL Java_cc0_NativeExample_init
(JNIEnv* env, jobject obj)
{
JwMat* mat = JwMat::matptr;
cout << "Java_cc0_NativeExample_init START" << endl;
if (mat == NULL) {
cout << "Java_cc0_NativeExample_init Mat-Wrapper created" << endl;
mat = new JwMat(env);
JwMat::matptr = new JwMat(env);
}
cout << "Java_cc0_NativeExample_init END" << endl;
}
Expand All @@ -30,6 +29,7 @@ JNIEXPORT void JNICALL Java_cc0_NativeExample_process
jobject matobj, jint frameId)
{
cout << "Java_cc0_NativeExample_process CALLED " << frameId << endl;
JwMat* mat = JwMat::matptr;
int cols = mat->cols(env, matobj);
int rows = mat->rows(env, matobj);
cout << "rows=" << rows << ", cols=" << cols << endl;
Expand Down
46 changes: 46 additions & 0 deletions jniplugin/native/src/main/native/VideoEqualizer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <stdio.h>
#include <stdlib.h>
#include <iostream>

#include "nativeCode.h" // generated by javah via maven-native-plugin

#include "opencv2/core/core.hpp"
#include "JwMat.h"
#include "jni_helper.h"
#include "cv_helper.h"

using namespace std;
using namespace cv;

JNIEXPORT void JNICALL Java_de_screenflow_frankenstein_vf_jni_VideoEqualizer_init
(JNIEnv* env, jobject obj)
{
JwMat* mat = JwMat::matptr;
if (mat == NULL) {
JwMat::matptr = new JwMat(env);
}
}

JNIEXPORT void JNICALL Java_de_screenflow_frankenstein_vf_jni_VideoEqualizer_process
(JNIEnv* env, jobject obj,
jobject matobj, jint frameId)
{
JwMat* mat = JwMat::matptr;
int cols = mat->cols(env, matobj);
int rows = mat->rows(env, matobj);
cout << "rows=" << rows << ", cols=" << cols << endl;

int channels = mat->channels(env, matobj);
if (channels<3) {
J_THROW("java/lang/Error", "channels < 3: "+mat->channels(env, matobj));
return;
}

int c0 = (unsigned char)POINT_CHANNEL_VALUE((cols>>1),(rows>>1),0,mat);
int c1 = (unsigned char)POINT_CHANNEL_VALUE((cols>>1),(rows>>1),1,mat);
int c2 = (unsigned char)POINT_CHANNEL_VALUE((cols>>1),(rows>>1),2,mat);
cout << "RGB-values at " << (rows>>1) << "," << (cols>>1) << ": " <<
c2 << "/" << c1 << "/" << c0 << endl ;

}

1 change: 1 addition & 0 deletions jniplugin/native/win64/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<javahClassNames>
<javahClassName>cc0.JniExample</javahClassName>
<javahClassName>cc0.NativeExample</javahClassName>
<javahClassName>de.screenflow.frankenstein.vf.jni.VideoEqualizer</javahClassName>
</javahClassNames>
</configuration>
<goals>
Expand Down

0 comments on commit 7d421fe

Please sign in to comment.