We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I got those two, and want to combine them but really, everything is false... Can someone help me out? first
// Click the mouse to memorize a current background image
import processing.video.*;
import gab.opencv.*;
// Variable for capture device
Capture video;
OpenCV opencv;
// Saved background
PImage backgroundImage;
// How different must a pixel be to be a foreground pixel
float threshold = 20;
void setup() {
String[] cameras = Capture.list();
//printArray(cameras);
size(1280, 720);
//video.width = 1280;
//video.height = 720;
video = new Capture(this, 1280, 720, cameras[76]);
video.start();
opencv = new OpenCV(this, 1280, 720);
opencv.startBackgroundSubtraction(5, 3, 0.5);
// Create an empty image the same size as the video
backgroundImage = createImage(video.width, video.height, RGB);
}
void captureEvent(Capture video) {
// Read image from the camera
video.read();
}
void draw() {
if (video.available() == true) {
video.read();
}
image(video, random(width),random(height));
opencv.loadImage(video);
opencv.updateBackground();
opencv.dilate();
opencv.erode();
noFill();
stroke(255, 0, 0);
strokeWeight(3);
for (Contour contour : opencv.findContours()) {
contour.draw();
}
}
void mousePressed() {
}
** **second code to combine with first one**** **
import processing.video.*;
Capture video;
int signal = 0;
//the buffer for storing video frames
ArrayList frames;
//different program modes for recording and playback
int mode = 0;
int MODE_NEWBUFFER = 0;
int MODE_RECORDING = 1;
int MODE_PLAYBACK = 2;
int currentX = 0;
void setup() {
size(640, 480);
// This the default video input, see the GettingStartedCapture
// example if it creates an error
video = new Capture(this, width, height);
// Start capturing the images from the camera
video.start();
}
void captureEvent(Capture c) {
c.read();
//create a new buffer in case one is needed
if (mode == MODE_NEWBUFFER) {
frames = new ArrayList();
mode = MODE_RECORDING;
}
//record into the buffer until there are enough frames
if (mode == MODE_RECORDING) {
//copy the current video frame into an image, so it can be stored in the buffer
PImage img = createImage(width, height, RGB);
video.loadPixels();
arrayCopy(video.pixels, img.pixels);
frames.add(img);
//in case enough frames have been recorded, switch to playback mode
if (frames.size() >= width) {
mode = MODE_PLAYBACK;
}
}
}
void draw() {
loadPixels();
//code for the recording mode
if (mode == MODE_RECORDING) {
//set the image counter to 0
int currentImage = 0;
//begin a loop for displaying pixel columns
for (int x = 0; x < video.width; x++) {
//go through the frame buffer and pick an image using the image counter
if (currentImage < frames.size()) {
PImage img = (PImage)frames.get(currentImage);
//display a pixel column of the current image
if (img != null) {
img.loadPixels();
for (int y = 0; y < video.height; y++) {
pixels[x + y * width] = img.pixels[x + y * video.width];
}
}
currentImage++;
}
else {
break;
}
}
}
if (mode == MODE_PLAYBACK) {
for (int x = 0; x < video.width; x++) {
PImage img = (PImage)frames.get(x);
if (img != null) {
img.loadPixels();
for(int y = 0; y < video.height; y++) {
pixels[x + y * width] = img.pixels[currentX + y * video.width];
}
}
}
currentX++;
if(currentX >= video.width) {
mode = MODE_NEWBUFFER;
//reset the column counter
currentX = 0;
}
}
updatePixels();
}
Answers
Do NOT post duplicate discussions.
I have deleted the other two discussions
@Nicolejansen -- combine them how? Please describe what each sketch does, and what you want the combined sketch to do.