Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.zip
# .git currently not docker-ignored so that we can do 'git clean' automatically
dist/
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.zip
visicam.conf
#visicam.conf
/build/
/nbproject/private/
/lib/javacv-bin/
/dist/
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM ubuntu:16.04
RUN apt-get update
RUN apt-get -y -q --no-install-recommends install openjdk-8-jdk ant libopencv2.4
RUN apt-get -y -q --no-install-recommends install curl unzip
# RUN apt-get -y remove libopencv2.4
RUN adduser --no-gecos --disabled-password visicam
ADD . /home/visicam
RUN chown -R visicam /home/visicam
WORKDIR /home/visicam
USER visicam
# fetch javaCV if it wasn't downloaded yet
RUN test -d lib/javacv-bin/ || ./lib/fetch-javacv.sh
RUN ant clean && ant
EXPOSE 8080
CMD ant run
5 changes: 5 additions & 0 deletions build_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
set -e
# Run this script, then the visicam server will be opened on port 8080.
sudo docker build -t visicam .
sudo docker run -p 8080:8080 --rm -it visicam
Binary file modified lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions lib/fetch-javacv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
cd "$(dirname "$0")"
URL=https://search.maven.org/remotecontent?filepath=org/bytedeco/javacv-platform/1.3.2/javacv-platform-1.3.2-bin.zip
#URL=https://search.maven.org/remotecontent?filepath=org/bytedeco/javacv/1.2/javacv-1.2-bin.zip
curl $URL > javacv.zip
rm -r javacv-bin/
unzip javacv.zip
357 changes: 0 additions & 357 deletions lib/javacv-bin/LICENSE.txt

This file was deleted.

548 changes: 0 additions & 548 deletions lib/javacv-bin/README.txt

This file was deleted.

Binary file removed lib/javacv-bin/javacpp.jar
Binary file not shown.
Binary file removed lib/javacv-bin/javacv-android-arm.jar
Binary file not shown.
Binary file removed lib/javacv-bin/javacv-linux-x86.jar
Binary file not shown.
Binary file removed lib/javacv-bin/javacv-linux-x86_64.jar
Binary file not shown.
Binary file removed lib/javacv-bin/javacv-macosx-x86_64.jar
Binary file not shown.
Binary file removed lib/javacv-bin/javacv-windows-x86.jar
Binary file not shown.
Binary file removed lib/javacv-bin/javacv-windows-x86_64.jar
Binary file not shown.
Binary file removed lib/javacv-bin/javacv.jar
Binary file not shown.
5 changes: 0 additions & 5 deletions lib/javacv-pi/binary_versions.txt

This file was deleted.

Binary file removed lib/javacv-pi/javacpp.jar
Binary file not shown.
Binary file removed lib/javacv-pi/javacv-linux-arm.jar
Binary file not shown.
Binary file removed lib/javacv-pi/javacv.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/nblibraries.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
libs.CopyLibs.classpath=\
${base}/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar
libs.CopyLibs.displayName=CopyLibs Task
libs.CopyLibs.prop-version=1.0
libs.CopyLibs.prop-version=2.0
145 changes: 79 additions & 66 deletions nbproject/build-impl.xml

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions nbproject/genfiles.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
build.xml.data.CRC32=782127a7
build.xml.script.CRC32=1898b009
build.xml.stylesheet.CRC32=28e38971@1.53.1.46
build.xml.script.CRC32=5c4ea007
build.xml.stylesheet.CRC32=8064a381@1.75.2.48
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=782127a7
nbproject/build-impl.xml.script.CRC32=53b88f11
nbproject/build-impl.xml.stylesheet.CRC32=6ddba6b6@1.53.1.46
nbproject/build-impl.xml.script.CRC32=c9bd417e
nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.75.2.48
45 changes: 30 additions & 15 deletions nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
application.title=VisiCam
application.vendor=thommy
auxiliary.org-netbeans-spi-editor-hints-projects.perProjectHintSettingsFile=nbproject/cfg_hints.xml
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned:
Expand All @@ -29,29 +30,39 @@ endorsed.classpath=
excludes=
file.reference.gson-2.2.2.jar=lib/gson-2.2.2.jar
file.reference.javacpp.jar=lib/javacv-bin/javacpp.jar
file.reference.javacv-android-arm.jar=lib/javacv-bin/javacv-android-arm.jar
file.reference.javacv-linux-arm.jar=lib/javacv-pi/javacv-linux-arm.jar
file.reference.javacv-linux-x86.jar=lib/javacv-bin/javacv-linux-x86.jar
file.reference.javacv-linux-x86_64.jar=lib/javacv-bin/javacv-linux-x86_64.jar
file.reference.javacv-macosx-x86_64.jar=lib/javacv-bin/javacv-macosx-x86_64.jar
file.reference.javacv-windows-x86.jar=lib/javacv-bin/javacv-windows-x86.jar
file.reference.javacv-windows-x86_64.jar=lib/javacv-bin/javacv-windows-x86_64.jar
file.reference.javacv-platform.jar=lib/javacv-bin/javacv-platform.jar
file.reference.javacv.jar=lib/javacv-bin/javacv.jar
file.reference.opencv-android-arm.jar=lib/javacv-bin/opencv-android-arm.jar
file.reference.opencv-android-x86.jar=lib/javacv-bin/opencv-android-x86.jar
file.reference.opencv-linux-armhf.jar=lib/javacv-bin/opencv-linux-armhf.jar
file.reference.opencv-linux-ppc64le.jar=lib/javacv-bin/opencv-linux-ppc64le.jar
file.reference.opencv-linux-x86.jar=lib/javacv-bin/opencv-linux-x86.jar
file.reference.opencv-linux-x86_64.jar=lib/javacv-bin/opencv-linux-x86_64.jar
file.reference.opencv-macosx-x86_64.jar=lib/javacv-bin/opencv-macosx-x86_64.jar
file.reference.opencv-platform.jar=lib/javacv-bin/opencv-platform.jar
file.reference.opencv-windows-x86.jar=lib/javacv-bin/opencv-windows-x86.jar
file.reference.opencv-windows-x86_64.jar=lib/javacv-bin/opencv-windows-x86_64.jar
file.reference.opencv.jar=lib/javacv-bin/opencv.jar
includes=**
jar.archive.disabled=${jnlp.enabled}
jar.compress=false
jar.index=${jnlp.enabled}
javac.classpath=\
${file.reference.javacpp.jar}:\
${file.reference.javacv-android-arm.jar}:\
${file.reference.javacv-linux-x86.jar}:\
${file.reference.javacv-linux-x86_64.jar}:\
${file.reference.javacv-macosx-x86_64.jar}:\
${file.reference.javacv-windows-x86.jar}:\
${file.reference.javacv-windows-x86_64.jar}:\
${file.reference.javacv.jar}:\
${file.reference.javacv-linux-arm.jar}:\
${file.reference.gson-2.2.2.jar}
${file.reference.gson-2.2.2.jar}:\
${file.reference.javacv-platform.jar}:\
${file.reference.opencv-android-arm.jar}:\
${file.reference.opencv-android-x86.jar}:\
${file.reference.opencv-linux-armhf.jar}:\
${file.reference.opencv-linux-ppc64le.jar}:\
${file.reference.opencv-linux-x86.jar}:\
${file.reference.opencv-linux-x86_64.jar}:\
${file.reference.opencv-macosx-x86_64.jar}:\
${file.reference.opencv-platform.jar}:\
${file.reference.opencv-windows-x86.jar}:\
${file.reference.opencv-windows-x86_64.jar}:\
${file.reference.opencv.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
Expand Down Expand Up @@ -85,6 +96,10 @@ jnlp.signing=
jnlp.signing.alias=
jnlp.signing.keystore=
main.class=com.t_oster.visicam.VisiCam
# Optional override of default Codebase manifest attribute, use to prevent RIAs from being repurposed
manifest.custom.codebase=
# Optional override of default Permissions manifest attribute (supported values: sandbox, all-permissions)
manifest.custom.permissions=
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
Expand Down
88 changes: 52 additions & 36 deletions src/com/t_oster/visicam/CameraController.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package com.t_oster.visicam;

import com.googlecode.javacv.FrameGrabber.Exception;
import com.googlecode.javacv.OpenCVFrameGrabber;
import static com.googlecode.javacv.cpp.opencv_calib3d.*;
import static com.googlecode.javacv.cpp.opencv_core.*;
import com.googlecode.javacv.cpp.opencv_core.CvMat;
import com.googlecode.javacv.cpp.opencv_core.CvMemStorage;
import com.googlecode.javacv.cpp.opencv_core.CvPoint;
import com.googlecode.javacv.cpp.opencv_core.CvPoint2D32f;
import com.googlecode.javacv.cpp.opencv_core.CvPoint3D32f;
import com.googlecode.javacv.cpp.opencv_core.CvSeq;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
import static com.googlecode.javacv.cpp.opencv_imgproc.*;

import org.bytedeco.javacv.FrameGrabber.Exception;
import org.bytedeco.javacv.OpenCVFrameGrabber;
import org.bytedeco.javacpp.opencv_imgproc;

import static org.bytedeco.javacpp.opencv_calib3d.*;
import static org.bytedeco.javacpp.opencv_core.*;
import org.bytedeco.javacpp.opencv_core.CvMat;
import static org.bytedeco.javacpp.opencv_imgproc.*;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
Expand All @@ -30,12 +27,16 @@
import java.nio.file.Paths;
import java.nio.file.Path;
import javax.imageio.ImageIO;
import org.bytedeco.javacpp.indexer.FloatRawIndexer;
import org.bytedeco.javacv.Frame;
import org.bytedeco.javacv.Java2DFrameConverter;
import org.bytedeco.javacv.OpenCVFrameConverter;

/**
*
* @author Thomas Oster <thomas.oster@rwth-aachen.de>
*/
public class CameraController
public class CameraController
{
private volatile CvMat homographyMatrix = null;
private final Boolean synchronizedCamera = false; // Dummy variable only used for camera access synchronization
Expand All @@ -45,6 +46,22 @@ public class CameraController
private final Boolean visicamRPiGPUFileLockSynchronization = false; // Dummy variable only used for file lock synchronization
// visicamRPiGPU integration end

private final Java2DFrameConverter frameConverter = new Java2DFrameConverter();
private final OpenCVFrameConverter.ToMat matConverter = new OpenCVFrameConverter.ToMat();


private Mat toMat(BufferedImage b)
{
return matConverter.convert(frameConverter.convert(b));
}

private BufferedImage toBufferedImage(Mat i)
{
return frameConverter.convert(matConverter.convert(i));
}



public InputStream toJpegStream(final BufferedImage img) throws IOException
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Expand Down Expand Up @@ -103,8 +120,8 @@ else if (command == null || "".equals(command))
grabber.setImageHeight(height);
grabber.setImageWidth(width);
grabber.start();
IplImage img = grabber.grab();
result = img.getBufferedImage();
Frame img = grabber.grab();
result = frameConverter.convert(img);
grabber.stop();
}
}
Expand Down Expand Up @@ -152,31 +169,30 @@ public BufferedImage getDummyImage(String filename, String txt) throws IOExcepti
public RelativePoint findMarker(BufferedImage input, RelativeRectangle roi)
{
Rectangle abs = roi.toAbsoluteRectangle(input.getWidth(), input.getHeight());
IplImage in = IplImage.createFrom(input.getSubimage(abs.x, abs.y, abs.width, abs.height));
IplImage gray = IplImage.create(in.width(), in.height(), in.depth(), 1);
cvCvtColor(in, gray, CV_BGR2GRAY);
cvErode(gray, gray, null, 1);
cvErode(gray, gray, null, 1);
cvDilate(gray, gray, null, 1);
cvDilate(gray, gray, null, 1);
cvErode(gray, gray, null, 1);
cvDilate(gray, gray, null, 1);
CvMemStorage storage = cvCreateMemStorage(0);
Mat in = toMat(input.getSubimage(abs.x, abs.y, abs.width, abs.height));
cvtColor(in, in, CV_BGR2GRAY);
Mat k = opencv_imgproc.getStructuringElement(opencv_imgproc.MORPH_RECT, new Size(2,2));
opencv_imgproc.erode(in, in, k);
opencv_imgproc.erode(in, in, k);
opencv_imgproc.dilate(in, in, k);
opencv_imgproc.dilate(in, in, k);
opencv_imgproc.erode(in, in, k);
opencv_imgproc.dilate(in, in, k);
double minDist = 10;
double cannyThreshold = 50;
double minVotes = 15;
int minRad = 5;
int maxRad = 25;
CvSeq circles = cvHoughCircles(gray, storage, CV_HOUGH_GRADIENT, 1, minDist, cannyThreshold, minVotes, minRad, maxRad);
if (circles.total() >= 1)
Mat circles = new Mat();
HoughCircles(in, circles, CV_HOUGH_GRADIENT, 1, minDist, cannyThreshold, minVotes, minRad, maxRad);
if (circles.cols() >= 1)
{
CvPoint3D32f point = new CvPoint3D32f(cvGetSeqElem(circles, 0));
CvPoint center = cvPointFrom32f(new CvPoint2D32f(point.x(), point.y()));
RelativePoint result = new RelativePoint((center.x()+abs.x)/(double)input.getWidth(), (center.y()+abs.y)/(double)input.getHeight());
cvReleaseMemStorage(storage);
FloatRawIndexer i = circles.createIndexer();
double x = i.get(0,0);
double y = i.get(0,1);
RelativePoint result = new RelativePoint((x+abs.x)/(double)input.getWidth(), (y+abs.y)/(double)input.getHeight());
return result;
}
cvReleaseMemStorage(storage);
return null;
}

Expand All @@ -198,9 +214,9 @@ public BufferedImage applyHomography(BufferedImage img)
{
if (homographyMatrix != null)
{
IplImage in = IplImage.createFrom(img);
cvWarpPerspective(in, in, homographyMatrix);
return in.getBufferedImage();
Mat in = toMat(img);
warpPerspective(in, in, cvarrToMat(homographyMatrix), in.size());
return toBufferedImage(in);
}
else
{
Expand Down Expand Up @@ -231,7 +247,7 @@ public void updateHomographyMatrix(BufferedImage img, RelativePoint[] markerPosi
dst.put(3, 0, 1, img.getHeight());

CvMat localHomographyMatrix = CvMat.create(3, 3);
cvFindHomography(src, dst, localHomographyMatrix, CV_RANSAC, 1, null);
cvFindHomography(src, dst, localHomographyMatrix); // TODO important parameters (CV_RANSAC) were removed for testing

// Write matrix values to file for visicamRPiGPU if needed
if (visicamRPiGPUEnabled)
Expand Down
2 changes: 1 addition & 1 deletion src/com/t_oster/visicam/VisiCamServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package com.t_oster.visicam;

import com.google.gson.Gson;
import com.googlecode.javacv.FrameGrabber;
import org.bytedeco.javacv.FrameGrabber;
import gr.ktogias.NanoHTTPD;
import java.awt.BasicStroke;
import java.awt.Color;
Expand Down
1 change: 1 addition & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dummyCapture.jpg
Binary file added test/dummy1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/dummy2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/dummy3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/dummy4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions test/dummyCapture.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
cd $(dirname $0)
sleep 0.4
touch dummyCapture.jpg
cmp dummyCapture.jpg dummy1.jpg && cp dummy2.jpg dummyCapture.jpg && exit 0
cmp dummyCapture.jpg dummy2.jpg && cp dummy3.jpg dummyCapture.jpg && exit 0
cmp dummyCapture.jpg dummy3.jpg && cp dummy4.jpg dummyCapture.jpg && exit 0
cp dummy1.jpg dummyCapture.jpg

32 changes: 32 additions & 0 deletions visicam.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#VisiCam Configuration
#Sat Jul 15 21:42:07 CEST 2017
markerSearchfields[3][y]=0.6133333333333333
markerSearchfields[2][x]=0
markerSearchfields[1][height]=0.40444444444444444
markerSearchfields[2][width]=0.34125
lockInsecureSettings=false
captureCommand=./test/dummyCapture.sh
markerSearchfields[1][width]=0.29
markerSearchfields[0][y]=0.17777777777777778
visicamRPiGPUBinaryPath=
markerSearchfields[2][y]=0.6088888888888889
markerSearchfields[1][x]=0.71
markerSearchfields[2][height]=0.39111111111111113
inputHeight=1050
visicamRPiGPUInactivitySeconds=
refreshSeconds=10
markerSearchfields[3][width]=0.3125
markerSearchfields[0][height]=0.06888888888888889
markerSearchfields[0][width]=0.095
cameraIndex=0
markerSearchfields[3][x]=0.6875
visicamRPiGPUMatrixPath=
outputHeight=1050
captureResult=./test/dummyCapture.jpg
markerSearchfields[1][y]=0
markerSearchfields[0][x]=0.08875
visicamRPiGPUImageProcessedPath=
inputWidth=1680
markerSearchfields[3][height]=0.38666666666666666
visicamRPiGPUImageOriginalPath=
outputWidth=1680