2017-10-10 13 views
0

나는이 범위를 벗어나야하지만이 오류의 맨 아래로 갈 수는 없습니다. 내 Mac 카메라의 피드를 기록하고 각 녹음 "세션"을 PImage 배열에 저장하는 스케치를 작성하려고 시도하고 세션 목록 (PImage [] ArrayList)에 추가합니다. 나는 'Replay'클래스를 사용하여 메모리에 저장된 이미지에 액세스하여 임의의 위치에서 재생합니다. 아래 코드는 IDE로 바로 복사 할 수 있어야합니다.처리 중 : 웹캠 저장 및 재생 버그

도움을 주시면 감사하겠습니다. 재생 개체가 항상 라이브 이미지를 표시하는 이유를 모르겠습니다. 감사!

import processing.video.*; 
Capture cam; 

ArrayList<PImage[]> allImages; 
ArrayList<PImage> currentImages; 
ArrayList<Replay> replays; 

boolean recording = false; 
boolean finishedSaving = true; 
int currentIndex = 0; 

void setup() { 
    size(1056, 704, P2D); 
    frameRate(30); 

    allImages = new ArrayList<PImage[]>(); 
    currentImages = new ArrayList<PImage>(); 
    replays = new ArrayList<Replay>(); 

    String[] cams = Capture.list(); 
    if (cams.length == 0) { 
    println("No cams!"); 
    exit(); 
    } else { 
    cam = new Capture(this, 1056, 704, cams[0], 30); 
    cam.start(); 
    } 

} 

void draw() { 
    background(0); 

    if (cam.available() == true) { 
    cam.read(); 
    } 


    for (Replay r : replays) { 
    r.display(); 
    } 

    if (recording) { 
    currentImages.add(cam); 
    noFill(); 
    stroke(255, 0, 0); 
    strokeWeight(5); 
    rect(0, 0, cam.width/3, cam.height/3); 
    } else { 
    saveToArray(); 
    } 

    image(cam, 0, 0, cam.width/3, cam.height/3); 

} 

void saveToArray() { 
    if (!finishedSaving) { 
    PImage[] tempImages = currentImages.toArray(new PImage[currentImages.size()]); 
    allImages.add(tempImages); 
    currentImages.clear(); 
    println("Finished saving to allImages array"); 
    println("allImages array size now = " + allImages.size()); 

    replays.add(new Replay(currentIndex)); 
    println("Added new Replay (index: " + currentIndex + ")"); 
    currentIndex++; 
    finishedSaving = true; 
    println(); 
    } 

} 

void keyPressed() { 
    if (key == 'r' || key == 'R') { 
    recording = !recording; 
    println("Recording: " + recording); 
    finishedSaving = false; 
    } 
} 

class Replay { 

    PVector position; 
    float w, h; 
    PImage[] images; 
    int count; 

Replay(int allImagesIndex) { 
    w = cam.width/3; 
    h = cam.height/3; 
    position = new PVector(random(width-w), random(height-h)); 
    count = 1; 
    images = allImages.get(allImagesIndex); 
} 

void display() { 
    image(images[count], position.x, position.y, w, h); 
    count++; 
    if (count > images.length-1) count = 1; 
} 

} 

답변

1

이렇게 보이는 것은 카메라 피드가 항상 각 개별 이미지에 지정 되었기 때문입니다. "현재"비디오 스트림 프레임의 "사본"을 얻으려면 피드에 .get()을 추가하여 픽셀을 가져 와서 PImage 변수에 저장합니다.

currentImages.add(cam.get());