2016-11-23 46 views
1

我正在嘗試製作我正在進行的藝術裝置的視覺效果,而且我不太清楚如何去處理它處理。這是我想怎麼辦(我將使用舊的CCTV監控):處理 - 隨機視頻陣列+攝像頭(使安全攝像頭類型的視覺效果)

  • 把屏幕劃分爲四個象限(就好像它是顯示從安全攝像頭的飼料,但我可以用視頻,在大多數情況下)

  • 有隨機視頻負載的象限(總數爲8個視頻),並有一定的秒數後的視頻變化(他們不都必須立刻改變,但無論什麼最容易)

  • 有一個網絡攝像頭髮送它的飼料到其中一個象限,就好像它是另一個視頻

(我總是可以解決的攝像頭,屏幕的四分之三之一,並加載隨機視頻到其他3個可用的象限,如果它簡化了的東西。)

我的加工技能是很基本的;到目前爲止,我已經設法將屏幕拆分爲4並加載4個視頻,但我真的不知道如何使用視頻陣列,這聽起來像是該程序執行我想要的更合理的方式。

這是基本的代碼:

import processing.video.*; 

Movie mov, mov1, mov2, mov3; 

    void setup() { 
     size(1280, 640); 
     frameRate(30); 
     mov = new Movie(this,"0.mov"); 
     mov1 = new Movie(this,"1.mov"); 
     mov2 = new Movie(this,"2.mov"); 
     mov3 = new Movie(this,"3.mov"); 

     mov.play(); 
     mov1.play(); 
     mov2.play(); 
     mov3.play(); 

     mov.volume(0); 
     mov1.volume(0); 
     mov2.volume(0); 
     mov3.volume(0); 
    } 

    void movieEvent(Movie mov) { 
     mov.read(); 
    } 

    void draw() { 
     image(mov, 0, 0, 640, 320); 
     image(mov1, 640, 0, 640, 320); 
     image(mov2, 0, 320, 640, 320); 
     image(mov3, 640, 320, 640, 320); 
    } 

我開始了與上面,然後試圖用視頻陣列工作,但只得到了這麼遠:

import processing.video.*; 

Capture cam; 

int maxmyMovies = 8; 
int myMoviesIndex = 0; 
Movie[] myMovies = new Movie[maxmyMovies]; 

void setup() { 

size(640,480); 

cam = new Capture(this, 640, 480, 12); 
cam.start(); 
smooth(); 

    for (int i = 0; i < myMovies.length; i ++) { 
    myMovies[i] = new Movie(this, i + ".mov"); 

    } 
} 

void draw() { 
image(myMovies[myMoviesIndex], 0, 0); 

    if (key == 'r') myMoviesIndex = int(random(0,8)); 

} 

void movieEvent(Movie myMovies) { 
    myMovies.read(); 
} 

(以上只是從其他代碼複製/粘貼,我不想讓它在按下字母「r」而不是按一定的時間隨機化。)所以,你可以看到我在這裏輸了...我真的會感謝任何幫助。

謝謝!

回答

0

很高興你已經分裂你想實現到什麼步驟:

  1. 把屏幕劃分爲四個象限(就好像它是顯示從安全攝像頭的飼料,但我d是使用視頻,在大多數 部分)

  2. 有無隨機視頻負載那些象限(總數爲8個視頻),並具有後的視頻變化若干秒(他們不都必須一次更改,但無論是最簡單的)

  3. 有一個攝像頭髮送它的飼料進入,就好像它是另一個視頻

    象限之一

看起來你已經攻克了第一部分。

我會分裂第二部分進一步:

  1. 觸發若干秒後的變化(時間它)
  2. 選取一個隨機象限/視頻

觸發一個採取millis()和條件可以實現一定延遲後的動作。你可以看到一個例子和更多細節here

關於挑選隨機象限/視頻,你很接近:random()應該做的伎倆。更棘手的部分是你如何組織你的數據。 一種選擇是保持兩個陣列的軌道:

  1. 列表(陣列)的要顯示的視頻
  2. 指向的視頻上述列表的子集象限列表

視頻始終可以訪問,但只會顯示一個選區。只需將第一個列表(已加載的視頻列表)中的視頻索引存儲到第二個列表(視頻選擇)

我也建議養成將一組執行任務的指令分組到一個函數的習慣。這樣代碼將更容易閱讀/遵循,使用和特別重複使用。

我不知道,如果你熟悉的功能已經,如從頭開始編寫它們,但你已經使用它們了很多到目前爲止:)

如果你還沒有使用過,他們並不難接。 這是一個試圖簡化想法以立即使用一個想法。 例如,您已撥打smooth(),您已寫入void setup(){}並在其中放置了一組說明。

同樣你可以用任何你想要的名稱來定義自己的函數:

void myFunction(){ 
    println("myFunction is working!"); 
} 

然後你就可以輕鬆地調用:

myFunction(); 

例如

void draw(){ 

} 
void keyPressed(){ 
    myFunction(); 
} 
void myFunction() { 
    println("myFunction is working!"); 
    ellipse(random(width),random(height),10,10); 
} 

我承認,這不是最令人興奮的例子,但它應該證明定義和使用函數是多麼簡單。還有其他的細節,比如函數返回類型和參數,但是你可以放棄這些。

讓我們運用這些知識做一個功能randomises可當「R」鍵被按下時可以很容易地被稱爲視頻:

import processing.video.*; 

Capture cam; 

int maxmyMovies = 8; 
int myMoviesIndex = 0; 
Movie[] myMovies = new Movie[maxmyMovies]; 

int[] selection = {0,1,2,3}; 

void setup() { 

    size(640, 480); 

    cam = new Capture(this, 640, 480, 12); 
    cam.start(); 
    smooth(); 

    for (int i = 0; i < myMovies.length; i ++) { 
    myMovies[i] = new Movie(this, i + ".mov"); 
    } 

    selectRandomVideos(); 
} 

void selectRandomVideos(){ 
    //select random movie for each quadrant 
    for(int i = 0 ; i < selection.length; i++){ 
    //random() returns a float and the index in an int, therefore we cast to (int) 
    //this also has the side effect to rounding down (similar to floor()) which is convenient as we need 7 as the highest index 
    selection[i] = (int)random(0,maxmyMovies); 
    myMovies[selection[i]].loop(); 
    myMovies[selection[i]].volume(0); 
    } 
} 

void draw() { 
    //top left 
    image(myMovies[selection[0]], 0, 0); 
    //top right 
    image(myMovies[selection[1]], 640, 0); 
    //bottom left 
    image(myMovies[selection[2]], 0, 480); 
    //bottom right 
    image(myMovies[selection[3]], 640, 480); 
} 

void keyPressed(){ 
    if(key == 'r') selectRandomVideos(); 
} 

void movieEvent(Movie myMovies) { 
    myMovies.read(); 
} 

注:上面的代碼沒有經過測試和視頻的大小沒有設置(所以無論您是否擁有正確分辨率的視頻,或者像以前一樣撥打image()時設置了寬度/高度)。代碼可能不會按原樣運行,但希望應該說明解決上述問題的方法。

因此,這是隨機播放視頻的一種非常基本的方式,它可以同時對所有視頻進行播放。此功能的進行調整,在一次處理單個視頻:

void selectRandomVideo(){ 
    //select random movie for one quadrant 
    //pick a quadrant 
    int randomQuadrant = (int)random(4); 
    //pick a video 
    int randomVideo = (int)random(maxmyMovies); 
    //store the random video index in the random quadrant 
    selection[randomQuadrant] = randomVideo; 
    //loop the random quadant's video and mute 
    myMovies[selection[randomQuadrant]].loop(); 
    myMovies[selection[randomQuadrant]].volume(0); 
} 

和集成:

import processing.video.*; 

Capture cam; 

int maxmyMovies = 8; 
int myMoviesIndex = 0; 
Movie[] myMovies = new Movie[maxmyMovies]; 

int[] selection = {0,1,2,3}; 

void setup() { 

    size(640, 480); 

    cam = new Capture(this, 640, 480, 12); 
    cam.start(); 
    smooth(); 

    for (int i = 0; i < myMovies.length; i ++) { 
    myMovies[i] = new Movie(this, i + ".mov"); 
    } 

    selectRandomVideos(); 
} 

void selectRandomVideos(){ 
    //select random movie for each quadrant 
    for(int i = 0 ; i < selection.length; i++){ 
    //random() returns a float and the index in an int, therefore we cast to (int) 
    //this also has the side effect to rounding down (similar to floor()) which is convenient as we need 7 as the highest index 
    selection[i] = (int)random(0,maxmyMovies); 
    myMovies[selection[i]].loop(); 
    myMovies[selection[i]].volume(0); 
    } 
} 
void selectRandomVideo(){ 
    //select random movie for one quadrant 
    //pick a quadrant 
    int randomQuadrant = (int)random(4); 
    //pick a video 
    int randomVideo = (int)random(maxmyMovies); 
    //store the random video index in the random quadrant 
    selection[randomQuadrant] = randomVideo; 
    //loop the random quadant's video and mute 
    myMovies[selection[randomQuadrant]].loop(); 
    myMovies[selection[randomQuadrant]].volume(0); 
} 
void draw() { 
    //top left 
    image(myMovies[selection[0]], 0, 0); 
    //top right 
    image(myMovies[selection[1]], 640, 0); 
    //bottom left 
    image(myMovies[selection[2]], 0, 480); 
    //bottom right 
    image(myMovies[selection[3]], 640, 480); 
} 

void keyPressed(){ 
    if(key == 'r') selectRandomVideo(); 
} 

void movieEvent(Movie myMovies) { 
    myMovies.read(); 
} 

使用這樣的事情和millis()基於定時器應該解決的第二部分。

對於第三個部分,您可以使用相同的技巧。如果您使用for循環在象限中顯示視頻,而不是使用重複的image()調用,則可能會有所幫助。在循環中,您可以使用條件來決定象限是否需要顯示視頻或相機饋送。

我們可以使用一個獨立的變量來跟蹤哪些象限應相機顯示在,然後放在一起,使用隨機設置這個值的基本功能:

void selectRandomCameraQuadrant(){ 
    //selects a valid index (0-3) or an invalid one (4) which means disable the camera 
    cameraIndex = (int)random(5); 
} 

有上述其中random(5)有點劈被用來代替random(4)。 這可能會讓我偶爾得到一個不是有效象限的索引,因此不會一直顯示攝像頭。

下面是使用此功能,而且「C」鍵,選擇一個隨機的攝像頭飼料象限的代碼版本:

import processing.video.*; 

Capture cam; 

int maxmyMovies = 8; 
int myMoviesIndex = 0; 
Movie[] myMovies = new Movie[maxmyMovies]; 

int[] selection = {0,1,2,3}; 

int cameraIndex = -1; 

void setup() { 

    size(640, 480); 

    cam = new Capture(this, 640, 480, 12); 
    cam.start(); 
    smooth(); 

    for (int i = 0; i < myMovies.length; i ++) { 
    myMovies[i] = new Movie(this, i + ".mov"); 
    } 

    selectRandomVideos(); 
} 

void selectRandomVideos(){ 
    //select random movie for each quadrant 
    for(int i = 0 ; i < selection.length; i++){ 
    //random() returns a float and the index in an int, therefore we cast to (int) 
    //this also has the side effect to rounding down (similar to floor()) which is convenient as we need 7 as the highest index 
    selection[0] = (int)random(0,maxmyMovies); 
    myMovies[selection[0]].loop(); 
    myMovies[selection[0]].volume(0); 
    } 
} 
void selectRandomVideo(){ 
    //select random movie for one quadrant 
    //pick a quadrant 
    int randomQuadrant = (int)random(4); 
    //pick a video 
    int randomVideo = (int)random(maxmyMovies); 
    //store the random video index in the random quadrant 
    selection[randomQuadrant] = randomVideo; 
    //loop the random quadant's video and mute 
    myMovies[selection[randomQuadrant]].loop(); 
    myMovies[selection[randomQuadrant]].volume(0); 
} 

void selectRandomCameraQuadrant(){ 
    //selects a valid index (0-3) or an invalid one (4) which means disable the camera 
    cameraIndex = (int)random(5); 
} 

void draw() { 
    //movie quadrant index 
    int movieIndex = 0; 
    //loop through y 
    for(int yIndex = 0; yIndex < 2; yIndex++){ 
    //loop through x 
    for(int xIndex = 0; xIndex < 2; xIndex++){ 
     //calculate x position based on index 
     int x = xIndex * 640; 
     int y = yIndex * 480; 

     //check if the camera index matches any of the quadrants (if so display camera, otherwise display movie) 
     if(movieIndex == cameraIndex){ 
     image(cam, x, y); 
     }else{ 
     image(myMovies[selection[movieIndex]], x, y); 
     } 
     //increment movie quadrant index 
     movieIndex++; 
    } 
    } 
} 

void keyPressed(){ 
    if(key == 'r') selectRandomVideo(); 
    if(key == 'c') selectRandomCameraQuadrant(); 
} 

void movieEvent(Movie myMovies) { 
    myMovies.read(); 
} 

最後說明這不是解決的最好/最徹底的方法問題,但一個想法。有多種方法可以實現。

相關問題