use of com.github.sarxos.webcam.Webcam in project narchy by automenta.
the class RasterHierarchy method process.
/**
* Invoke to start the main processing loop.
*/
public void process() {
Webcam webcam = UtilWebcamCapture.openDefault(frameWidth, frameHeight);
// adjust the window size and let the GUI know it has changed
Dimension actualSize = webcam.getViewSize();
setPreferredSize(actualSize);
setMinimumSize(actualSize);
window.setMinimumSize(actualSize);
window.setPreferredSize(actualSize);
window.setVisible(true);
BufferedImage input;
while (running) {
/*
* Uncomment this section to scan the focal point across the frame
* automatically - just for demo purposes.
*/
/*
int xx = this.focusPoint.getX();
int yy = this.focusPoint.getY();
xx += 1;
if(xx > frameWidth)
{
xx = 0;
yy += 1;
if (yy > frameHeight)
yy = 0;
}
this.setFocus(xx, yy);
*/
input = webcam.getImage();
// synchronized (workImage) {
// copy the latest image into the work buffer
// Graphics2D g2 = workImage.createGraphics();
buffered = this.rasterizeImage(input);
// }
repaint();
}
}
use of com.github.sarxos.webcam.Webcam in project narchy by automenta.
the class WebcamTrack method main.
public static void main(String[] args) {
// tune the tracker for the image size and visual appearance
ConfigGeneralDetector configDetector = new ConfigGeneralDetector(-1, 8, 1);
PkltConfig configKlt = new PkltConfig(3, new int[] { 1, 2, 4, 8 });
PointTracker<ImageFloat32> tracker = FactoryPointTracker.klt(configKlt, configDetector, ImageFloat32.class, null);
// Open a webcam at a resolution close to 640x480
Webcam webcam = UtilWebcamCapture.openDefault(640, 480);
// Create the panel used to display the image and
ImagePanel gui = new ImagePanel();
gui.setPreferredSize(webcam.getViewSize());
ShowImages.showWindow(gui, "KLT Tracker");
int minimumTracks = 100;
while (true) {
BufferedImage image = webcam.getImage();
ImageFloat32 gray = ConvertBufferedImage.convertFrom(image, (ImageFloat32) null);
tracker.process(gray);
List<PointTrack> tracks = tracker.getActiveTracks(null);
// Spawn tracks if there are too few
if (tracks.size() < minimumTracks) {
tracker.spawnTracks();
tracks = tracker.getActiveTracks(null);
minimumTracks = tracks.size() / 2;
}
// Draw the tracks
Graphics2D g2 = image.createGraphics();
for (PointTrack t : tracks) {
VisualizeFeatures.drawPoint(g2, (int) t.x, (int) t.y, Color.RED);
}
gui.setBufferedImageSafe(image);
}
}
use of com.github.sarxos.webcam.Webcam in project BoofCV by lessthanoptimal.
the class ExampleCollectImages method main.
public static void main(String[] args) {
// Open a webcam at a resolution close to 640x480
Webcam webcam = Webcam.getWebcams().get(0);
UtilWebcamCapture.adjustResolution(webcam, 640, 480);
webcam.open();
// Create the panel used to display the image
ImagePanel gui = new ImagePanel();
gui.setPreferredSize(webcam.getViewSize());
gui.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
saveImage = true;
}
});
ShowImages.showWindow(gui, "Webcam", true);
int total = 0;
while (true) {
BufferedImage image = webcam.getImage();
if (saveImage) {
System.out.println("Saving image " + total);
saveImage = false;
UtilImageIO.saveImage(image, String.format("image%04d.png", (total++)));
}
gui.setImageUI(image);
}
}
use of com.github.sarxos.webcam.Webcam in project BoofCV by lessthanoptimal.
the class UtilWebcamCapture method openDefault.
/**
* Opens the default camera while adjusting its resolution
*/
public static Webcam openDefault(int desiredWidth, int desiredHeight) {
Webcam webcam = Webcam.getDefault();
// Webcam doesn't list all available resolutions. Just pass in a custom
// resolution and hope it works
adjustResolution(webcam, desiredWidth, desiredHeight);
webcam.open();
return webcam;
}
use of com.github.sarxos.webcam.Webcam in project BoofCV by lessthanoptimal.
the class UtilWebcamCapture method openDevice.
/**
* Searches for the first device which matches the pattern. Webcam capture doesn't name devices
* using the standard "/dev/video0" scheme, but it includes that in its name.
*
* @param deviceName Partial or complete name of the device you wish to pen
* @return The webcam it found
*/
public static Webcam openDevice(String deviceName, int desiredWidth, int desiredHeight) {
Webcam webcam = findDevice(deviceName);
if (webcam == null)
throw new IllegalArgumentException("Can't find camera " + deviceName);
adjustResolution(webcam, desiredWidth, desiredHeight);
webcam.open();
return webcam;
}
Aggregations