Skip to content

Drawing the cam to a PGraphics breaks the library #112

@clankill3r

Description

@clankill3r

This is the getting started capture example, slightly modified.
I added a PGraphics and draw the cam to there.
After that cam.available() will never equal to true anymore.

I added a line in the code:
//image(cam, 0, 0, width, height); // << uncommenting this will fix the issue
A draw to the main graphics before drawing to another PGraphics is fixing the issue.

This happens on OSX.
For me on 10.12.6 with processing 3.5.3.

I also tested this on another mac, with more likely a newer OS and there was also the problem.

/**
 * Getting Started with Capture.
 * 
 * Reading and displaying an image from an attached Capture device. 
 */

import processing.video.*;

Capture cam;


PGraphics pg;

void setup() {
  size(640, 480);

  String[] cameras = Capture.list();

  if (cameras == null) {
    println("Failed to retrieve the list of available cameras, will try the default...");
    cam = new Capture(this, 640, 480);
  } if (cameras.length == 0) {
    println("There are no cameras available for capture.");
    exit();
  } else {
    println("Available cameras:");
    printArray(cameras);

    // The camera can be initialized directly using an element
    // from the array returned by list():
    cam = new Capture(this, cameras[0]);
    // Or, the settings can be defined based on the text in the list
    //cam = new Capture(this, 640, 480, "Built-in iSight", 30);
    
    // Start capturing the images from the camera
    cam.start();
  }
  
  pg = createGraphics(width, height);
  pg.beginDraw();
  pg.endDraw();
}




void draw() {
  if (cam.available() == true) {
    cam.read();
    pg.beginDraw();
    //image(cam, 0, 0, width, height); // << uncommenting this will fix the issue
    pg.image(cam, 0, 0);
    pg.endDraw();
  }
  image(cam, 0, 0, width, height);
  // The following does the same as the above image() line, but 
  // is faster when just drawing the image without any additional 
  // resizing, transformations, or tint.
  //set(0, 0, cam);
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions