Skip to content
Snippets Groups Projects
Commit 667f16f3 authored by Amandine  TOURNAY's avatar Amandine TOURNAY
Browse files

Added project

parent f2f24cf3
No related branches found
No related tags found
No related merge requests found
.idea/
target/
.settings/
*.iml
.project
.classpath
\ No newline at end of file
pom.xml 0 → 100644
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- Inherited Icy Parent POM -->
<parent>
<groupId>org.bioimageanalysis.icy</groupId>
<artifactId>parent-pom-plugin</artifactId>
<version>1.0.3</version>
</parent>
<!-- Project Information -->
<artifactId>opencv</artifactId>
<version>4.5.1</version>
<packaging>jar</packaging>
<name>OpenCV</name>
<description>OpenCV (Open Computer Vision) library for Icy. see more at http://opencv.org</description>
<url>http://icy.bioimageanalysis.org/plugin/opencv/</url>
<inceptionYear>2020</inceptionYear>
<organization>
<name>Institut Pasteur</name>
<url>https://pasteur.fr</url>
</organization>
<licenses>
<license>
<name>GNU GPLv3</name>
<url>https://www.gnu.org/licenses/gpl-3.0.en.html</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<id>sdallongeville</id>
<name>Stéphane Dallongeville</name>
<url>https://research.pasteur.fr/fr/member/stephane-dallongeville/</url>
<roles>
<role>founder</role>
<role>lead</role>
<role>architect</role>
<role>developer</role>
<role>debugger</role>
<role>tester</role>
<role>maintainer</role>
<role>support</role>
</roles>
</developer>
</developers>
<!-- Project properties -->
<properties>
</properties>
<!-- Project build configuration -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>${project.artifactId}-fetch</id>
<phase>generate-sources</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includeArtifactIds>opencv</includeArtifactIds>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<stripVersion>true</stripVersion>
<excludeTransitive>true</excludeTransitive>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<!-- List of project's dependencies -->
<dependencies>
<!-- The core of Icy -->
<dependency>
<groupId>org.bioimageanalysis.icy</groupId>
<artifactId>icy-kernel</artifactId>
</dependency>
<dependency>
<groupId>org.openpnp</groupId>
<artifactId>opencv</artifactId>
<version>4.5.1-0</version>
</dependency>
</dependencies>
<!-- Icy Maven repository (to find parent POM) -->
<repositories>
<repository>
<id>icy</id>
<name>Icy's Nexus</name>
<url>https://icy-nexus.pasteur.fr/repository/Icy/</url>
</repository>
</repositories>
</project>
\ No newline at end of file
This diff is collapsed.
package plugins.adufour.opencv;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JSeparator;
import org.opencv.core.Mat;
import org.opencv.videoio.VideoCapture;
import org.opencv.videoio.Videoio;
import icy.image.IcyBufferedImage;
import icy.main.Icy;
import icy.math.FPSMeter;
import icy.sequence.Sequence;
import icy.sequence.SequenceAdapter;
import plugins.adufour.ezplug.EzPlug;
import plugins.adufour.ezplug.EzStoppable;
import plugins.adufour.ezplug.EzVar;
import plugins.adufour.ezplug.EzVarInteger;
import plugins.adufour.ezplug.EzVarListener;
import plugins.adufour.vars.util.VarException;
public class OpenCVCapture extends EzPlug implements EzStoppable, EzVarListener<Integer>
{
List<EzVarInteger> parameters = new ArrayList<EzVarInteger>();
VideoCapture camera = null;
@Override
protected void initialize()
{
OpenCV.initialize();
for (Field f : Videoio.class.getDeclaredFields())
{
String name = f.getName();
if (!name.startsWith("CAP_PROP_")) continue;
if (name.contains("_DC1394")) continue;
if (name.contains("_GIGA")) continue;
if (name.contains("_GPHOTO2")) continue;
if (name.contains("_GSTREAMER")) continue;
if (name.contains("_INTELPERC")) continue;
if (name.contains("_IOS")) continue;
if (name.contains("_OPENNI")) continue;
if (name.contains("_POS")) continue;
if (name.contains("_PVAPI")) continue;
if (name.contains("_XI")) continue;
name = name.substring(9).toLowerCase();
EzVarInteger setting = new EzVarInteger(name);
setting.setValue(Integer.valueOf(-1));
setting.addVarChangeListener(this);
parameters.add(setting);
}
int cpt = 0;
for (EzVarInteger setting : parameters)
{
addEzComponent(setting);
cpt++;
if (cpt % 20 == 0) addComponent(new JSeparator(JSeparator.VERTICAL));
}
}
@Override
protected void execute()
{
camera = new VideoCapture(0);
for (EzVarInteger setting : parameters)
{
if (setting.getValue() == -1) continue;
String propName = "CAP_PROP_" + setting.name.toUpperCase();
try
{
int propID = Videoio.class.getDeclaredField(propName).getInt(null);
camera.set(propID, setting.getValue());
}
catch (Exception e)
{
throw new VarException(setting.getVariable(), e.getMessage());
}
}
// Read the first image to initialize the meta-data
Mat mat = new Mat();
camera.read(mat);
IcyBufferedImage image = OpenCV.convertToIcy(mat);
// Create the sequence
final Sequence s = new Sequence("Live webcam", image);
Icy.getMainInterface().addSequence(s);
// don't update the channel bounds on update
image.setAutoUpdateChannelBounds(false);
s.setAutoUpdateChannelBounds(false);
// Closing the sequence should stop the camera
final Thread thread = Thread.currentThread();
s.addListener(new SequenceAdapter()
{
@Override
public void sequenceClosed(Sequence sequence)
{
s.removeListener(this);
thread.interrupt();
}
});
FPSMeter fps = new FPSMeter();
try
{
while (camera.read(mat) && !Thread.currentThread().isInterrupted())
{
OpenCV.convertToIcy(mat, image);
image.dataChanged();
fps.update();
getUI().setProgressBarMessage("Acquiring at " + fps.getFPS() + "fps");
}
}
catch (Exception e)
{
}
finally
{
camera.release();
}
}
@Override
public void clean()
{
for (EzVarInteger setting : parameters)
setting.removeVarChangeListener(this);
parameters.clear();
}
@Override
public void variableChanged(EzVar<Integer> source, Integer newValue)
{
if (camera == null) return;
String propName = "CAP_PROP_" + source.name.toUpperCase();
try
{
int propID = Videoio.class.getDeclaredField(propName).getInt(null);
camera.set(propID, newValue);
}
catch (Exception e)
{
throw new VarException(source.getVariable(), e.getMessage());
}
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment