电脑技术:Getting Started with Kinect and Processing[转载]
转载自:Getting Started with Kinect and Processing | Daniel Shiffman
Getting Started with Kinect and Processing
Kinect and Processing
The Microsoft Kinect sensor is a peripheral device (designed for XBox and windows PCs) that functions much like a webcam. However, in addition to providing an RGB image, it also provides a depth map. Meaning for every pixel seen by the sensor, the Kinect measures distance from the sensor. This makes a variety of computer vision problems like background removal, blob detection, and more easy and fun!
The Kinect sensor itself only measures color and depth. However, once that information is on your computer, lots more can be done like “skeleton” tracking (i.e. detecting a model of a person and tracking his/her movements). To do skeleton tracking you’ll need to use Thomas Lengling’s windows-only Kinect v2 processing libray. However, if you’re on a Mac and all you want is raw data from the Kinect, you are in luck! This library uses libfreenect and libfreenect2 open source drivers to access that data for Mac OS X (windows support coming soon).
电脑技术+建模+艺术:一个很牛的沉浸式交互网站——踏得网
Processing实现GameofLife
这是在Processing官网上找到的一个例子:A Processing implementation of Game of Life
程序源代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
// Size of cells int cellSize = 5; // How likely for a cell to be alive at start (in percentage) float probabilityOfAliveAtStart = 15; // Variables for timer int interval = 100; int lastRecordedTime = 0; // Colors for active/inactive cells color alive = color(0, 200, 0); color dead = color(0); // Array of cells int[][] cells; // Buffer to record the state of the cells and use this while changing the others in the interations int[][] cellsBuffer; // Pause boolean pause = false; void setup() { size (640, 360); // Instantiate arrays cells = new int[width/cellSize][height/cellSize]; cellsBuffer = new int[width/cellSize][height/cellSize]; // This stroke will draw the background grid stroke(48); noSmooth(); // Initialization of cells for (int x=0; x<width/cellSize; x++) { for (int y=0; y<height/cellSize; y++) { float state = random (100); if (state > probabilityOfAliveAtStart) { state = 0; } else { state = 1; } cells[x][y] = int(state); // Save state of each cell } } background(0); // Fill in black in case cells don't cover all the windows } void draw() { //Draw grid for (int x=0; x<width/cellSize; x++) { for (int y=0; y<height/cellSize; y++) { if (cells[x][y]==1) { fill(alive); // If alive } else { fill(dead); // If dead } rect (x*cellSize, y*cellSize, cellSize, cellSize); } } // Iterate if timer ticks if (millis()-lastRecordedTime>interval) { if (!pause) { iteration(); lastRecordedTime = millis(); } } // Create new cells manually on pause if (pause && mousePressed) { // Map and avoid out of bound errors int xCellOver = int(map(mouseX, 0, width, 0, width/cellSize)); xCellOver = constrain(xCellOver, 0, width/cellSize-1); int yCellOver = int(map(mouseY, 0, height, 0, height/cellSize)); yCellOver = constrain(yCellOver, 0, height/cellSize-1); // Check against cells in buffer if (cellsBuffer[xCellOver][yCellOver]==1) { // Cell is alive cells[xCellOver][yCellOver]=0; // Kill fill(dead); // Fill with kill color } else { // Cell is dead cells[xCellOver][yCellOver]=1; // Make alive fill(alive); // Fill alive color } } else if (pause && !mousePressed) { // And then save to buffer once mouse goes up // Save cells to buffer (so we opeate with one array keeping the other intact) for (int x=0; x<width/cellSize; x++) { for (int y=0; y<height/cellSize; y++) { cellsBuffer[x][y] = cells[x][y]; } } } } void iteration() { // When the clock ticks // Save cells to buffer (so we opeate with one array keeping the other intact) for (int x=0; x<width/cellSize; x++) { for (int y=0; y<height/cellSize; y++) { cellsBuffer[x][y] = cells[x][y]; } } // Visit each cell: for (int x=0; x<width/cellSize; x++) { for (int y=0; y<height/cellSize; y++) { // And visit all the neighbours of each cell int neighbours = 0; // We'll count the neighbours for (int xx=x-1; xx<=x+1;xx++) { for (int yy=y-1; yy<=y+1;yy++) { if (((xx>=0)&&(xx<width/cellSize))&&((yy>=0)&&(yy<height/cellSize))) { // Make sure you are not out of bounds if (!((xx==x)&&(yy==y))) { // Make sure to to check against self if (cellsBuffer[xx][yy]==1){ neighbours ++; // Check alive neighbours and count them } } // End of if } // End of if } // End of yy loop } //End of xx loop // We've checked the neigbours: apply rules! if (cellsBuffer[x][y]==1) { // The cell is alive: kill it if necessary if (neighbours < 2 || neighbours > 3) { cells[x][y] = 0; // Die unless it has 2 or 3 neighbours } } else { // The cell is dead: make it live if necessary if (neighbours == 3 ) { cells[x][y] = 1; // Only if it has 3 neighbours } } // End of if } // End of y loop } // End of x loop } // End of function void keyPressed() { if (key=='r' || key == 'R') { // Restart: reinitialization of cells for (int x=0; x<width/cellSize; x++) { for (int y=0; y<height/cellSize; y++) { float state = random (100); if (state > probabilityOfAliveAtStart) { state = 0; } else { state = 1; } cells[x][y] = int(state); // Save state of each cell } } } if (key==' ') { // On/off of pause pause = !pause; } if (key=='c' || key == 'C') { // Clear all for (int x=0; x<width/cellSize; x++) { for (int y=0; y<height/cellSize; y++) { cells[x][y] = 0; // Save all to zero } } } } |
使用说明:
按空格键暂停,并可以用鼠标点击格子来激活/取消激活某个格点,再按空格继续。
按R键重置并随机生成一些格点。
按C清空所有格点。
请查看全文看在线展示。
Processing:音乐舞动效果
在广场的大屏幕上看到了随韵律跳动的闪烁图谱,就想知道用Processing该怎样编出来这样的效果呢?于是就出现了下面的拙劣产品。
优点:有点效果了;
缺点:不能随韵律跳动,也没有节奏,需要改进。
源代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
void setup() { size(600, 600); smooth(); background(0); colorMode(RGB,255); noFill(); } void draw() { for(int d=0;d<80;d+=10) { for(int x=50;x<640;x+=100) { for(int y=50;y<640;y+=100) { stroke(random(255),random(255),random(255)); strokeWeight(4); rectMode(CENTER); //fill(random(255),random(255),random(255),50); rect(x,y,d,d); } } } } |
效果:
学习Arduino:用Arduino控制Procssing中的图形
编程:Processing 和 Java 中的 OpenCV 库
学习:Processing学习笔记
这段时间初步学习了一下Processing编程,现在贴上所学的部分结果,以备查用。
[slideshow_deploy id=’7866′]
下面贴上一个好玩的~
Processing编程:调用video库播放视频的一个心得
Processing可以播放视频,对视频进行简单处理,生成视频等等。可是自己编的程序却一直都打不开视频,而运行例子却很正常。我使用的是 processing-2.0b9-windows32 版本,是在学习《Processing互动编程艺术》的第9.1节时遇到这个问题的。本以为是编码的问题,但是把例子中自带的“transit.mov”视频拿来用还是打不开。真是百思不得其解。因为是在初学,完全是照着例子写的,检查多次都没有错。 于是在processing.org上去找原因。
最后才发现是少了视频不间断读取这一块:
[cc lang=”java”]
// Called every time a new frame is available to read
void movieEvent(Movie m) {
m.read();
}
[/cc]
加上之后就成功运行了。
既然是要说心得,现在说说找的时候学到了什么。我首先找到了 Video library (视频库)(地址:http://processing.org/reference/libraries/video/index.html)。查看库的说明后发现,需要安装Quicktime才行。原文说“For the Processing Video library to work, it is necessary to have QuickTime installed on your computer. Download and install QuickTime (or iTunes, which includes QuickTime). Other solutions such as QuickTime Alternative or QT Lite will not work and should be avoided.”(原文地址:http://wiki.processing.org/w/Video_Issues)。但是奇怪的是,没有安装Quicktime的我,程序自带的例子是可以运行的啊。我想肯定是我的电脑安装了QQ影音,估计里面包含了解码程序,所以我就不用再安装 QuickTime 了。一般就是这一,只要系统中安装了解码程序就可以解码视频了。说需要安装 QuickTime,其实也就是说要安装 *.mov 的解码程序罢了。既然可以运行,于是就仔细看例子。
WordPress技术+编程:在WordPress中怎样插入Processing程序并能实时运行?使用插件!(附用法)
我们可以使用插件很方便的插入Processing程序。
下面的这几个插件名字很像。第一个是Processing.js(插件目录中其名字为processing-js)、第二个是Processing JS(两个词之间有空格)(插件目录中其名字为processingjs(之间无空格))、第三个是Processing-js-Easy(插件目录中其名字为processing-js-easy),注意区别。
Processing.js(Processing-js)
下载地址:http://wordpress.org/plugins/processing-js/
安装方法:把 “processing-js/”上传到 “ /wp-content/plugins/” 目录。在后台激活即可。
使用方法:待整理。
Processing JS 插件
插件下载地址:http://wordpress.org/plugins/processingjs/
安装方法:下载解压后放到 /wp-content/plugins/ 中,然后在后台激活即可使用。
使用方法:激活后,在HTML模式下的编辑器上将多出一个“processing”按钮,如下图所示。点击它之后将在文章中插入一个简单的Processing程序代码,你可以用它当模版修改,或者直接贴上自己的代码即可。
还可以在这里找到更多的例子(附带代码)和用法:Processing JS Demos
Processing JS官网:http://processingjs.org/
举例: