Difference between revisions of "Team:NYU Shanghai/Code"
Line 844: | Line 844: | ||
<span></span><span></span><span></span><span></span><br>b[yi]=dv[bsum]; | <span></span><span></span><span></span><span></span><br>b[yi]=dv[bsum]; | ||
− | < | + | <br><br><span></span><span></span><span></span>f (y==0) { |
− | <span></span><span></span><span></span><span></span><span></span | + | <br><span></span><span></span><span></span><span></span><span></span>vmin[x]=min(x+radius+1, wm); |
− | <span></span><span></span><span></span><span></span | + | <br><span></span><span></span><span></span><span></span> vmax[x]=max(x-radius, 0); |
− | <span></span><span></span><span></span><span></span><br> | + | <br><span></span><span></span><span></span><span></span>} |
− | <span></span><span></span><span></span><span></span | + | <br><span></span><span></span><span></span><span></span>p1=pix[yw+vmin[x]]; |
− | < | + | <br><br><span></span><span></span><span></span><span></span>p2=pix[yw+vmax[x]]; |
− | < | + | <br><br><span></span><span></span><span></span><span></span>rsum+=((p1 & 0xff0000)-(p2 & 0xff0000))>>16; |
− | <span></span><span></span><span></span><span></span | + | <br><span></span><span></span><span></span><span></span>gsum+=((p1 & 0x00ff00)-(p2 & 0x00ff00))>>8; |
− | <span></span><span></span><span></span><span></span | + | <br><span></span><span></span><span></span><span></span>bsum+= (p1 & 0x0000ff)-(p2 & 0x0000ff); |
− | <span></span><span></span><span></span><span></span | + | <br><br><br><span></span><span></span><span></span><span></span>yi++; |
− | <span></span><span></span><span></span><br> | + | <br><span></span><span></span><span></span>} |
− | <span></span><span></span><span></span | + | <br><span></span><span></span><span></span>yw+=w; |
− | <span></span | + | <br><span></span> } |
− | < | + | <br><br><span></span><span></span>for (x=0; x<w; x++) { |
− | <span></span><span></span><span></span | + | <br><span></span><span></span><span></span>rsum=gsum=bsum=0; |
− | <span></span><span></span><span></span | + | <br><span></span><span></span><span></span>yp=-radius*w; |
− | <span></span><span></span><span></span | + | <br><span></span><span></span><span></span>for (i=-radius; i<=radius; i++) { |
− | <span></span><span></span><span></span><span></span | + | <br><span></span><span></span><span></span><span></span>yi=max(0, yp)+x; |
− | <span></span><span></span><span></span><span></span | + | <br><span></span><span></span><span></span><span></span>rsum+=r[yi]; |
− | <span></span><span></span><span></span><span></span | + | <br><span></span><span></span><span></span><span></span>gsum+=g[yi]; |
− | <span></span><span></span><span></span><span></span | + | <br><span></span><span></span><span></span><span></span>bsum+=b[yi]; |
− | <span></span><span></span><span></span><span></span | + | <br><span></span><span></span><span></span><span></span>yp+=w; |
− | <span></span><span></span><span></span><br> | + | <br><span></span><span></span><span></span>} |
− | <span></span><span></span><span></span | + | <br><span></span><span></span><span></span>yi=x; |
− | <span></span><span></span><span></span | + | <br><span></span><span></span><span></span>for (y=0; y<h; y++) { |
− | <span></span><span></span><span></span><span></span | + | <br><span></span><span></span><span></span><span></span>pix[yi]=0xff000000 | (dv[rsum]<<16) | (dv[gsum]<<8) | dv[bsum]; |
− | <span></span><span></span><span></span><span></span | + | <br><span></span><span></span><span></span><span></span>if (x==0) { |
− | <span></span><span></span><span></span><span></span><span></span | + | <br><span></span><span></span><span></span><span></span><span></span>vmin[y]=min(y+radius+1, hm)*w; |
− | <span></span><span></span><span></span><span></span><span></span | + | <br><span></span><span></span><span></span><span></span><span></span>vmax[y]=max(y-radius, 0)*w; |
− | <span></span><span></span><span></span><span></span><br> | + | <br><span></span><span></span><span></span><span></span>} |
− | <span></span><span></span><span></span><span></span | + | <br><span></span><span></span><span></span><span></span>p1=x+vmin[y]; |
− | <span></span><span></span><span></span><span></span | + | <br><span></span><span></span><span></span><span></span>p2=x+vmax[y]; |
− | < | + | <br><br><span></span><span></span><span></span><span></span>rsum+=r[p1]-r[p2]; |
− | <span></span><span></span><span></span><span></span | + | <br><span></span><span></span><span></span><span></span>gsum+=g[p1]-g[p2]; |
− | <span></span><span></span><span></span><span></span | + | <br><span></span><span></span><span></span><span></span>bsum+=b[p1]-b[p2]; |
− | < | + | <br><br><span></span><span></span><span></span><span></span>yi+=w; |
− | <span></span><span></span><span></span><br> | + | <br><span></span><span></span><span></span>} |
− | <span></span><span></span><br> | + | <br><span></span><span></span>} |
− | <span></span | + | <br><span></span>} |
− | < | + | <br><br><span></span>void save_blob() { |
− | < | + | <br><br><span></span><span></span>Blob b; |
− | <span></span><span></span | + | <br><span></span><span></span>blobs=new float[theBlobDetection.getBlobNb ()][4]; |
− | <span></span><span></span | + | <br><span></span><span></span>for (int n=0; n<theBlobDetection.getBlobNb (); n++) |
− | <span></span><span></span><br> | + | <br><span></span><span></span>{ |
− | <span></span><span></span><span></span | + | <br><span></span><span></span><span></span>b=theBlobDetection.getBlob(n); |
− | <span></span><span></span><span></span | + | <br><span></span><span></span><span></span>if (dist(block_size/2,block_size/2,b.xMin*block_size, |
− | <span></span><span></span><span></span><span></span | + | <br><span></span><span></span><span></span><span></span>b.yMin*block_size)<radius |
− | <span></span><span></span><span></span | + | <br><span></span><span></span><span></span>&&b.w*block_size>5&&b.w*block_size<25&& |
− | <span></span><span></span><span></span | + | <br><span></span><span></span><span></span>b.h*block_size>5&&b.h*block_size<25){ |
− | <span></span><span></span><span></span | + | <br><span></span><span></span><span></span>blobs[n][0]=b.xMin*block_size; |
− | <span></span><span></span><span></span | + | <br><span></span><span></span><span></span>blobs[n][1]=b.yMin*block_size; |
− | <span></span><span></span><span></span | + | <br><span></span><span></span><span></span>blobs[n][2]=b.w*block_size; |
− | <span></span><span></span><span></span | + | <br><span></span><span></span><span></span>blobs[n][3]=b.h*block_size; |
− | <span></span><span></span><br> | + | <br><span></span><span></span>} |
− | <span></span><span></span><br> | + | <br><span></span><span></span>} |
− | <span></span | + | <br><span></span>} |
− | < | + | <br><br><span></span>void convert() { |
− | <span></span><span></span | + | <br><span></span><span></span>int row, col, i; |
− | <span></span><span></span | + | <br><span></span><span></span>for (int n=0; n<sequence.length; n++) { |
− | <span></span><span></span><span></span | + | <br><span></span><span></span><span></span>sequence[n]=false; |
− | <span></span><span></span><br> | + | <br><span></span><span></span>} |
− | <span></span><span></span | + | <br><span></span><span></span>for (int n=0; n<blobs.length; n++) { |
− | <span></span><span></span><span></span | + | <br><span></span><span></span><span></span>row=int(blobs[n][0]+blobs[n][2]*0.5)/grid_size; |
− | <span></span><span></span><span></span | + | <br><span></span><span></span><span></span>col=int(blobs[n][1]+blobs[n][3]*0.5)/grid_size; |
− | <span></span><span></span><span></span | + | <br><span></span><span></span><span></span>i=row+col*grid_num; |
− | <span></span><span></span | + | <br><span></span><span></span>if (i>0&&i<grid_num*grid_num) { |
− | <span></span><span></span><span></span><span></span | + | <br><span></span><span></span><span></span><span></span>sequence[i]=true; |
− | <span></span><span></span><span></span><br>} | + | <br><span></span><span></span><span></span><br>} |
− | <span></span><span></span><br> | + | <br><span></span><span></span>} |
− | <span></span | + | <br><span></span>} |
− | < | + | <br><br><span></span>void draw_grid() { |
− | <span></span><span></span | + | <br><span></span><span></span>pushMatrix(); |
− | <span></span><span></span | + | <br><span></span><span></span>translate(a, b); |
− | <span></span><span></span | + | <br><span></span><span></span>rectMode(CORNER); |
− | <span></span><span></span | + | <br><span></span><span></span>int x=0; |
− | <span></span><span></span | + | <br><span></span><span></span>int y=0; |
− | <span></span><span></span | + | <br><span></span><span></span>noStroke(); |
− | <span></span><span></span | + | <br><span></span><span></span>fill(0); |
− | <span></span><span></span | + | <br><span></span><span></span>rect(-interval,-interval,(grid_size+interval)*grid_num+interval*2, |
− | <span></span><span></span | + | <br><span></span><span></span>(grid_size+interval)*grid_num+interval*2); |
− | <span></span><span></span | + | <br><span></span><span></span>for (int i=0; i<sequence.length; i++) { |
− | <span></span><span></span><span></span | + | <br><span></span><span></span><span></span>x=(grid_size+interval)*(i%grid_num); |
− | <span></span><span></span><span></span><br>y=(grid_size+interval)*(i/grid_num); | + | <br><span></span><span></span><span></span><br>y=(grid_size+interval)*(i/grid_num); |
− | <span></span><span></span><span></span><span></span><br><br>noStroke(); | + | <br><br><span></span><span></span><span></span><span></span><br><br>noStroke(); |
<span></span><span></span><span></span> | <span></span><span></span><span></span> | ||
− | <span></span><span></span><span></span><br><br>if (sequence[i]) { | + | <br><br><span></span><span></span><span></span><br><br>if (sequence[i]) { |
− | <span></span><span></span><span></span><span></span><br>fill(avg_color[0], avg_color[1], avg_color[2]); | + | <br><span></span><span></span><span></span><span></span><br>fill(avg_color[0], avg_color[1], avg_color[2]); |
− | <span></span><span></span><span></span><br>} else { | + | <br><span></span><span></span><span></span><br>} else { |
− | <span></span><span></span><span></span> <br>fill(70); | + | <br><span></span><span></span><span></span> <br>fill(70); |
− | <span></span><span></span><span></span><br>} | + | <br><span></span><span></span><span></span><br>} |
− | <span></span><span></span><span></span><br>rect(x, y, grid_size, grid_size); | + | <br><span></span><span></span><span></span><br>rect(x, y, grid_size, grid_size); |
− | <span></span><span></span><br>} | + | <br><span></span><span></span><br>} |
− | <span></span><span></span><br>popMatrix(); | + | <br><span></span><span></span><br>popMatrix(); |
− | <span></span><br>} | + | <br><span></span><br>} |
− | <span></span><br><br>void glow(int n) { | + | <br><br><span></span><br><br>void glow(int n) { |
− | <span></span><span></span><br>pushMatrix(); | + | <br><span></span><span></span><br>pushMatrix(); |
− | <span></span><span></span><br>translate(a, b); | + | <br><span></span><span></span><br>translate(a, b); |
− | <span></span><span></span><br>rectMode(CORNER); | + | <br><span></span><span></span><br>rectMode(CORNER); |
− | <span></span><span></span><br>for (int m=0; m<grid_num; m++) { | + | <br><span></span><span></span><br>for (int m=0; m<grid_num; m++) { |
− | <span></span><span></span><span></span><br>if (sequence[m*grid_num+n]) { | + | <br><span></span><span></span><span></span><br>if (sequence[m*grid_num+n]) { |
− | <span></span><span></span><span></span><span></span><br>for (int p=-1; p<2; p++) { | + | <br><span></span><span></span><span></span><span></span><br>for (int p=-1; p<2; p++) { |
− | <span></span><span></span><span></span><span></span><span></span><br>for (int q=-1; q<2; q++) { | + | <br><span></span><span></span><span></span><span></span><span></span><br>for (int q=-1; q<2; q++) { |
− | <span></span><span></span><span></span><span></span><span></span><span></span><br>if (n+p>=0&&n+p<grid_num&&m+q>=0&& | + | <br><span></span><span></span><span></span><span></span><span></span><span></span><br>if (n+p>=0&&n+p<grid_num&&m+q>=0&& |
− | <span></span><span></span><span></span><span></span><span></span><span></span><span></span><br>m+q<grid_num) { | + | <br><span></span><span></span><span></span><span></span><span></span><span></span><span></span><br>m+q<grid_num) { |
− | <span></span><span></span><span></span><span></span><span></span><span></span><span></span><br>noStroke(); | + | <br><span></span><span></span><span></span><span></span><span></span><span></span><span></span><br>noStroke(); |
− | <span></span><span></span><span></span><span></span><span></span><span></span><span></span><br><br>fill(255, 255, 255, 20); | + | <br><br><span></span><span></span><span></span><span></span><span></span><span></span><span></span><br><br>fill(255, 255, 255, 20); |
− | <span></span><span></span><span></span><span></span><span></span><span></span><span></span><br>rect((n+p)*(interval+grid_size), (m+q)*(interval+grid_size), | + | <br><span></span><span></span><span></span><span></span><span></span><span></span><span></span><br>rect((n+p)*(interval+grid_size), (m+q)*(interval+grid_size), |
<br><br><span></span><span></span><span></span><span></span><span></span><span></span><span></span>grid_size, grid_size); | <br><br><span></span><span></span><span></span><span></span><span></span><span></span><span></span>grid_size, grid_size); | ||
<br><span></span><span></span><span></span><span></span><span></span><span></span>} | <br><span></span><span></span><span></span><span></span><span></span><span></span>} | ||
Line 1,019: | Line 1,019: | ||
<br><br>Source: blob detection | <br><br>Source: blob detection | ||
http://www.v3ga.net/processing/BlobDetection/ | http://www.v3ga.net/processing/BlobDetection/ | ||
+ | |||
<br><br>soundcipher | <br><br>soundcipher | ||
<br>http://explodingart.com/soundcipher/ | <br>http://explodingart.com/soundcipher/ |
Revision as of 03:58, 18 September 2015