|
Author |
Topic: ahhh HELP!! java.langOutOfMemoryError (Read 644 times) |
|
K1diN5An3
|
ahhh HELP!! java.langOutOfMemoryError
« on: Dec 5th, 2004, 9:56am » |
|
this is a long and complicated post please stay with me. trying to generate some graphics based on basic computer vision, getting java.lang.OutOfMemoryError <<no stack trace available>> bet i am allocating many more objects then i think the computer vision assumes that we learn the background images (bgpixels) before things comes into the frame, then a basic pixel subtraction is done,(see diff_bright) in the function findMHI() in the MHI class. If from the pixel is not part of the background it becomes white, and if it is moving 10 is accumulativly subtracted from the white so as to make a gradient. Then from the gradient the magnitude and the orientation of the motion can be extracted (see convolution). trying to use a sobel gradient mask. All that works fine, but when i try to implement graphic generation similar to Andreas Gysin's Chronodraw using an array of BImages, everything goes haywire. I hope all this make sense to somebody... The code is in the next post because its exceeds the message memory limit. ahh so frustrated!
|
|
|
|
K1diN5An3
|
Re: ahhh HELP!! java.langOutOfMemoryError
« Reply #1 on: Dec 5th, 2004, 9:58am » |
|
code from the previous message, ALL the code would fit in this message either, so the mhi class is the next post.. fuck this so frustrating... nobody is going to read all this.. int bgpixels[]; int diffpix[]; int showdiffpix[]; int n_width = 160; int n_height = 120; int n_pix = n_width * n_height; int redmask = (255<<16); //0xFF hex 255 = 111111111 int greenmask = (255<<; int bluemask = 255; int bgR,bgG,bgB,bg_brightness; int hquads = 4; int vquads = 1; int quadwidth = 40; int quadheight = n_height; int bufferlength = 400; int framestep =6; int framerest =2; int framecounter =0; int currentpic = bufferlength-1; BImage[] frames = new BImage[bufferlength]; BImage start = new BImage(); MHI tester; void setup(){ size(640,480); beginVideo(n_width,n_height,30); tester = new MHI(); bgpixels = new int[n_pix]; diffpix = new int[n_pix]; showdiffpix = new int[n_pix]; start.width = quadwidth; start.height = quadheight; start.pixels = new color[quadwidth*quadheight]; for(int k =0; k< n_pix; k++){ bgpixels[k]=0; diffpix[k]=0; showdiffpix[k]=0; } for(int i=0; i<n_pix;i+=10){ bgpixels[i] = video.pixels[i]; } for(int j=0; j<start.pixels.length;j++){ start.pixels[j] = color(150,0,0); } clearBuffer(); } void keyPressed(){ switch(key){ case 'b': for(int i=0; i<n_pix;i++){ color b = video.pixels[i]; bgR = (b & redmask) >>16; bgG = (b & greenmask) >>8; bgB = (b & bluemask); bg_brightness = (bgR+bgG+bgB)/3; bgpixels[i] = bg_brightness; } break; case ' ': clearBuffer(); break; } } void clearBuffer(){ for(int a=0; a< frames.length;a++){ frames[a] = start.copy(); } } void loop(){ // image(video,160,120); showdiffpix = tester.findMHI(); // classic kludge, bad idea. int i=0; int row, loc; for (int y=0; y<n_height; y++){ row = y * width; for (int x=0; x<n_width; x++){ loc = row + x; pixels[loc] = showdiffpix[i]; i++; } } for(int j=0; j<vquads; j++){ for(int m=0; m<hquads; m++){ set(m*quadwidth, j*quadheight, frames[currentpic]); currentpic+= framestep; currentpic = currentpic%bufferlength; if (currentpic<0) currentpic = bufferlength + currentpic; } } framecounter++; if(framecounter > framerest){ framecounter = 0; currentpic--; if(currentpic <0) currentpic = bufferlength -1; } }
|
|
|
|
K1diN5An3
|
Re: ahhh HELP!! java.langOutOfMemoryError
« Reply #2 on: Dec 5th, 2004, 10:01am » |
|
this is the last of it. and where i bet the problems are... class MHI{ int white,black,threshold,colorbit,offsetbit,r,g,b; float brightnessPix, diff_bright,dpr,dpg,dpb; float csdr, csdg, csdb; color csdp, c, grayscale; int nw_,nw,n__,n_,ne_,ne,cw_,cw,c__,c_,ce_,ce,sw_,sw,s__,s_,se_,se,difx,dify ; int skip =8; int del =1; float dec = 10; boolean move = false; int [] mhi = new int[n_pix]; float [] gradiantOrientation = new float[n_pix]; int [] gradiantMagnitude = new int[n_pix]; MHI(){ offsetbit = 10; white = (colorbit<<16) + (colorbit<< + colorbit; black= 0; threshold = 20; for(int i=0;i<n_pix;i++){ mhi[i]=0; gradiantOrientation[i]=0; gradiantMagnitude[i]=0; } } int[] findMHI(){ //make sure to keep track of the coordinates of when movement starts and stops for (int i =0; i <n_pix; i++){ c = video.pixels[i]; r = (c & redmask) >>16; // g = (c & greenmask) >>8; b = (c & bluemask); brightnessPix= (r+b+g)/3.0; //int //currpixels[i] = brightnessPix; diff_bright = abs(brightnessPix - bgpixels[i]); dpr = 0; dpg = 0; dpb = 0; if (diff_bright > threshold){ dpr = 255; dpg = 255; dpb = 255; } csdp = mhi[i]; if(((red(csdp) - offsetbit) > 0) ||((green(csdp) - offsetbit)>0)||((blue(csdp) - offsetbit)>0)) {move=true;} csdr = max (0, red(csdp) - offsetbit); csdg = max (0, green(csdp) - offsetbit); csdb = max (0, blue(csdp) - offsetbit); csdr = min(255, csdr + dpr); csdg = min(255, csdg + dpg); csdb = min(255, csdb + dpb); grayscale = color (csdr,csdg,csdb); mhi[i] = grayscale; } //smoothmhi(mhi); convolution(mhi); return mhi; } void drawdot(int qx, int qy){ int offsx = qx%quadwidth; int offsy = qy%quadheight; int mx = qx / quadwidth; int my = qy / quadheight; int offsp = mx + my * hquads; int cp = (currentpic + offsp * framestep) % bufferlength; if (cp < 0) cp = bufferlength + cp; frames[cp].set(offsx, offsy, color(200,255,255)); } //Bresenham's algorithm void drawline(float x1, float y1, float x2, float y2){ { int sizex, sizey, incx, incy,drawx,drawy; int countx, county, x, y; sizex=(int)x2-(int)x1; sizey=(int)y2-(int)y1; if(sizex<0) { sizex=-sizex; incx=-1; } else { incx=1; } if(sizey<0) { sizey=-sizey; incy=-1; }else { incy = 1; } countx=(int)x1; county=(int)y1; drawx = (int)x1; drawy = (int)y1; drawdot(drawx, drawy); if (sizex>=sizey) { y=sizex>>1; for(int i=0;i<sizex;i++) { y+=sizey; if (y>=sizex) { y-=sizex; county+=incy; } countx+=incx; drawdot(countx, county); } } else { x=sizey>>1; for(int i=0;i<sizey;i++) { x+=sizex; if (x>=sizey) { x-=sizey; countx+=incx; } county+=incy; drawdot(countx, county); } } } } void convolution(int[] mhi){ int sobelx=0; int sobely=0; float dx,dy; float px =1; float py=1; float constant =1; for(int y = skip; y < (160-skip); y+=skip) { for(int x = skip; x < (120-skip); x+=skip) { nw_ = (x-del)*(y-del); n__ = x*(y-del); ne_ = (x+del)*(y-del); cw_ = (x-del)*(y); c__ = x*y; ce_ = (x+del)*(y); sw_ = (x-del)*(y+del); s__ = x*(y+del); se_ =(x+del)*(y+del); nw = mhi[nw_]; n_ = mhi[n__]; ne = mhi[ne_]; cw = mhi[cw_]; c_ = mhi[c__]; px = mhi[c__]; ce = mhi[ce_]; sw = mhi[sw_]; s_ = mhi[s__]; se = mhi[se_]; //sum of the differences in x difx = (ne - n_)+(n_ - nw)+(ce - c_)+(c_ - cw)+(se - s_)+(s_ - sw); //sum of the differnces in y dify = (nw - cw)+(cw - sw)+(n_ - c_)+(c_ - s_)+(ne - ce)+(ce - se); //if pixels are zero don't use them //if pixels are surrounded by 0 if( (c_ != 0) && (nw !=0) && (n_ !=0) && (ne!=0) && (cw !=0) && (ce!=0) && (sw!=0) && (s_ !=0) && (se !=0) && (move==true)) // and if the differences in x an y are really big orreally small { sobelx = (ne * -1)+(n_ * 0)+(nw * 1)+(ce * -2)+(c_ * 0)+(cw * 2)+(se *-1)+(s_ * 0)+(sw * 1); sobely = (ne * -1)+(n_ * -2)+(nw * -1)+(ce * 0)+(c_ * 0)+(cw * 0)+(se *-1)+(s_ * 2)+(sw * 1); gradiantMagnitude[c__] = abs(sobelx) + abs(sobely); gradiantOrientation[c__]= atan2(sobely,sobelx); dx = gradiantMagnitude[c__] * sin(gradiantOrientation[c__]+(PI/2)) * constant; dy = gradiantMagnitude[c__] * sin(gradiantOrientation[c__]) * constant; px += dx; py += dy; if(random(1)>.9){ drawline(px,py,dx,dy); } } } } } }
|
|
|
|
Philipp
|
Re: ahhh HELP!! java.langOutOfMemoryError
« Reply #3 on: Dec 10th, 2004, 3:45pm » |
|
I don't think it's your MHI class. I can replicate your problem with this code: Code: BImage[] bar = new BImage[600]; void setup () { BImage ba = new BImage(); ba.width = 200; ba.height = 200; ba.pixels = new color[200*200]; for (int i=0; i <bar.length;i++) { bar[i] = ba.copy(); } } void loop() { } |
| What's interesting is that it works the first time I run it and refuses to work the second time, so my guess is that there are problems with the garbage collection of the BImages. Using int[][] arrays instead of the BImage[] array doesn't help though. Adding the following code rectified the situation on my machine. See if you can do something similar. Code: public void stop() { for (int i=0; i <bar.length;i++) { bar[i] = null; } } |
| If that doesn't help try increasing the memory for Processing. (check the readme file to see how you can do that.)
|
« Last Edit: Dec 10th, 2004, 3:46pm by Philipp » |
|
|
|
|
|