Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
quekky committed May 2, 2017
0 parents commit e93d347
Show file tree
Hide file tree
Showing 15 changed files with 2,141 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
AdvancedCameraSettings_r3
=========================

This program is for webcams to persistent the config

Usage
-----

1. java -jar AdvancedCameraSettings.jar
2. Config all the webcams
3. Save the config, so that config.ini is created
4. during windows startup, run the loadconfig.bat (you can do a file shortcut at C:\Trakomatic\Cron\@reboot)


Credits
-------

(Codes from https://obsproject.com/forum/threads/using-2-or-more-logitech-c920s-or-c930es-together-successfully.26707/ ,
edited by Cxrus)
73 changes: 73 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="AdvancedCameraSettings" default="default" basedir=".">
<description>Builds, tests, and runs the project AdvancedCameraSettings.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar: JAR building
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="AdvancedCameraSettings-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->
</project>
Binary file added lib/dsj.dll
Binary file not shown.
Binary file added lib/dsj.jar
Binary file not shown.
124 changes: 124 additions & 0 deletions src/AdvancedCameraSettingsMain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import com.digitalmodular.utilities.ConfigManager;
import de.humatic.dsj.CaptureDeviceControls;
import java.util.ArrayList;

import util.CameraFormatSelectionDialog;
import util.CameraSelectionDialog;
import util.DirectShowCamera;
import de.humatic.dsj.DSFilterInfo;
import de.humatic.dsj.DSMediaType;
import java.util.Map;

/**
* @author Mark Jeronimus
*/
// date 2014/08/05
public class AdvancedCameraSettingsMain {
public static void main(String[] args) throws Exception {
if(args.length > 0 && args[0].equals("--load") ) {
loadCamerasSettings();
} else {
DirectShowCamera[] cameras = queryCameras();

if (cameras.length == 0)
System.exit(0);

new MultiCameraTestMain(cameras);
}
}

private static DirectShowCamera[] queryCameras() {
DSFilterInfo[] cameraInfos = DirectShowCamera.getCameras();
ArrayList<DSFilterInfo> camerasToExclude = new ArrayList<DSFilterInfo>();
ArrayList<DirectShowCamera> cameras = new ArrayList<DirectShowCamera>();
DSFilterInfo cameraInfo = null;
int i = 1;

do {
CameraSelectionDialog cd = new CameraSelectionDialog("Select camera " + i, cameraInfos, camerasToExclude);
cameraInfo = cd.getSelectedCamera();
if (cameraInfo == null)
break;

CameraFormatSelectionDialog cfd = new CameraFormatSelectionDialog("Select format for camera " + i,
DirectShowCamera.getFormats(cameraInfo));
DSMediaType format = cfd.getSelectedFormat();
if (format == null)
break;

camerasToExclude.add(cameraInfo);

DirectShowCamera camera = new DirectShowCamera(cameraInfo);
camera.selectFormat(format);
cameras.add(camera);
i++;
} while (cameraInfo != null);

return cameras.toArray(new DirectShowCamera[cameras.size()]);
}

public AdvancedCameraSettingsMain() {

}


private static final int[][] propertyKeys = {
{CaptureDeviceControls.EXPOSURE, CaptureDeviceControls.GAIN, CaptureDeviceControls.BRIGHTNESS,
CaptureDeviceControls.CONTRAST, CaptureDeviceControls.SATURATION, CaptureDeviceControls.HUE,
CaptureDeviceControls.COLORENABLE, CaptureDeviceControls.WHITEBALANCE, CaptureDeviceControls.GAMMA},
{CaptureDeviceControls.BACKLIGHTCOMPENSATION, CaptureDeviceControls.SHARPNESS, CaptureDeviceControls.INPUT_LEVEL,
CaptureDeviceControls.INPUT_SELECT},
{CaptureDeviceControls.FOCUS, CaptureDeviceControls.IRIS, CaptureDeviceControls.ZOOM, CaptureDeviceControls.PAN,
CaptureDeviceControls.TILT, CaptureDeviceControls.ROLL},
{CaptureDeviceControls.MASTER_VOL, CaptureDeviceControls.MASTER_PAN, CaptureDeviceControls.TREBLE,
CaptureDeviceControls.BASS, CaptureDeviceControls.BALANCE},
{CaptureDeviceControls.CAMCONTROL_ABSOLUTE, CaptureDeviceControls.CAMCONTROL_AUTO,
CaptureDeviceControls.CAMCONTROL_MANUAL, CaptureDeviceControls.CAMCONTROL_RELATIVE},
{CaptureDeviceControls.VC_FLIP_HOR, CaptureDeviceControls.VC_FLIP_VER, CaptureDeviceControls.VC_TRIGGER,
CaptureDeviceControls.VC_TRIGGER_ENABLE},
{CaptureDeviceControls.LT_DIGITAL_PAN, CaptureDeviceControls.LT_DIGITAL_PANTILTZOOM,
CaptureDeviceControls.LT_DIGITAL_TILT, CaptureDeviceControls.LT_DIGITAL_ZOOM,
CaptureDeviceControls.LT_EXPOSURE_TIME, CaptureDeviceControls.LT_FACE_TRACKING, CaptureDeviceControls.LT_FINDFACE,
CaptureDeviceControls.LT_LED} };

private static void loadCamerasSettings() {
DSFilterInfo[] cameraInfos = DirectShowCamera.getCameras();
ConfigManager.revert();
Map<String, String> data = ConfigManager.getAllData();

for(DSFilterInfo cameraInfo : cameraInfos) {
DirectShowCamera camera = new DirectShowCamera(cameraInfo);

try {
camera.start();
for (int j = 0; j < propertyKeys.length; j++) {
for (int i = 0; i < propertyKeys[j].length; i++) {

try {
String value = data.get(camera.getPath() + "?" + propertyKeys[j][i]);
if(value != null) {
System.out.println("Set "+camera.getName()+" value "+propertyKeys[j][i]+" to "+value);
camera.setParameterValue(propertyKeys[j][i], Integer.parseInt(value));
}
}
catch(Exception e) {}

try {
String value = data.get(camera.getPath() + "&" + propertyKeys[j][i]);
if(value != null) {
System.out.println("Set "+camera.getName()+" auto "+propertyKeys[j][i]+" to "+value);
camera.setAuto(propertyKeys[j][i], Boolean.parseBoolean(value));
}
}
catch(Exception e) {}
}
}
camera.stop();
}
catch(Exception e) {
System.out.println(e);
}
}

}
}
97 changes: 97 additions & 0 deletions src/MultiCameraTestMain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;

import javax.swing.JFrame;
import javax.swing.Timer;

import util.CameraSettingsPanel;
import util.DirectShowCamera;
import util.FrameListener;

import com.digitalmodular.utilities.swing.ImagePanel;

/**
* @author Mark Jeronimus
* @version 1.0
* @since 1.0
* @date 2012/04/03
*/
public class MultiCameraTestMain extends JFrame implements FrameListener {
private final DirectShowCamera[] cameras;
private ImagePanel[] images;

public MultiCameraTestMain(final DirectShowCamera[] cameras) throws Exception {
super("Dual camera test");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.cameras = cameras;
images = new ImagePanel[cameras.length];

for (int i = 0; i < cameras.length; i++) {
DirectShowCamera camera = cameras[i];

images[i] = new ImagePanel(true);

camera.addFrameListener(this);
camera.start();
}

{
Timer t = new Timer(1000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("initializeComponents");
initializeComponents();
setSize(400 * cameras.length, 600);
setLocationRelativeTo(null);
setVisible(true);
}
});
t.setRepeats(false);
t.start();
}
}

void initializeComponents() {
setLayout(new GridLayout(2, cameras.length));

for (DirectShowCamera camera : cameras)
add(new CameraSettingsPanel(camera));

for (int i = 0; i < cameras.length; i++) {
add(images[i]);
}
}

@Override
public synchronized void newFrame(Object source, byte[] data) {
// Catch exceptions because somewhere up the call tree it is silently
// caught and not reported.
try {
int index = -1;
for (int i = 0; i < cameras.length; i++) {
if (cameras[i] == source) {
index = i;
break;
}
}

int width = cameras[index].getFormat().getWidth();
int height = cameras[index].getFormat().getHeight();

BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
byte[] array = ((DataBufferByte)image.getRaster().getDataBuffer()).getData();
System.arraycopy(data, 0, array, 0, array.length);

images[index].setImage(image);

repaint();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
Loading

0 comments on commit e93d347

Please sign in to comment.