use of com.github.sarxos.webcam.Webcam in project BoofCV by lessthanoptimal.
the class WebcamCaptureWebcamInterface method open.
@Override
public <T extends ImageBase<T>> SimpleImageSequence<T> open(String device, int width, int height, ImageType<T> imageType) {
if (device != null) {
Webcam webcam;
try {
int which = Integer.parseInt(device);
webcam = Webcam.getWebcams().get(which);
} catch (NumberFormatException ignore) {
webcam = UtilWebcamCapture.findDevice(device);
}
if (webcam == null) {
throw new RuntimeException("Can't find webcam with ID or name at " + device);
}
try {
if (width >= 0 && height >= 0) {
UtilWebcamCapture.adjustResolution(webcam, width, height);
}
webcam.open();
return new SimpleSequence<>(webcam, imageType);
} catch (RuntimeException ignore) {
}
}
return new SimpleSequence<>(device, width, height, imageType);
}
use of com.github.sarxos.webcam.Webcam in project narchy by automenta.
the class WebcamObjectTrack method process.
/**
* Invoke to start the main processing loop.
*/
public void process() {
Webcam webcam = UtilWebcamCapture.openDefault(desiredWidth, desiredHeight);
// 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);
// create
T input = tracker.getImageType().createImage(actualSize.width, actualSize.height);
workImage = new BufferedImage(input.getWidth(), input.getHeight(), BufferedImage.TYPE_INT_RGB);
ImageFloat32 inputFloat = new ImageFloat32(actualSize.width, actualSize.height);
while (true) {
BufferedImage buffered = webcam.getImage();
ConvertBufferedImage.convertFrom(webcam.getImage(), input, true);
// mode is read/written to by the GUI also
int mode = this.mode;
boolean success = false;
if (mode == 2) {
Rectangle2D_F64 rect = new Rectangle2D_F64();
rect.set(point0.x, point0.y, point1.x, point1.y);
UtilPolygons2D_F64.convert(rect, target);
success = tracker.initialize(input, target);
this.mode = success ? 3 : 0;
} else if (mode == 3) {
success = tracker.process(input, target);
}
synchronized (workImage) {
// copy the latest image into the work buffered
Graphics2D g2 = workImage.createGraphics();
g2.drawImage(buffered, 0, 0, null);
ConvertBufferedImage.convertFrom(buffered, inputFloat);
fitCannyBinary(inputFloat, g2);
// visualize the current results
if (mode == 1) {
drawSelected(g2);
} else if (mode == 3) {
if (success) {
drawTrack(g2);
}
}
}
repaint();
}
}
use of com.github.sarxos.webcam.Webcam in project opennars by opennars.
the class RasterHierachy 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, buffered;
workImage = new BufferedImage(actualSize.width, actualSize.height, BufferedImage.TYPE_INT_RGB);
while (true) {
/*
* 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);
g2.drawImage(buffered, 0, 0, null);
}
repaint();
}
}
Aggregations