// FUNCTION THAT WILL BE CALLED IN PARENT CLASS public void createbg() { PImage canvas; // addational value float r = 1; // MASKE erstellen (Vignette) // begindraw and endraw are needed for pgraphics to work properly mask.beginDraw(); // make a black background mask.background(0); // center the anchorpoint mask.shapeMode(PConstants.CENTER); // make a white ellipse half as large as the canvas mask.fill(255); mask.ellipse(width / 2, height / 2, width / 1.3f, height / 1.3f); // resize for better blur compability (prevent crashes) mask.resize(width / 5, height / 5); mask.filter(PConstants.BLUR, 19); // restire full size. this will blur the image even further mask.resize(width / 2, height / 2); mask.endDraw(); // CREATE Picture pimg.beginDraw(); // make a black background pimg.background(0); // this will generate bubbles specified by the image (NOT FINISHED) for (int i = 0; i < img.width; i += parent.random(200)) { for (int j = 0; j < img.height; j += parent.random(200)) { pimg.fill(img.get(i, j)); pimg.noStroke(); pimg.shapeMode(PConstants.CENTER); pimg.ellipse(i + 1, j + 1, r, r); r = parent.random(0.2f, 200); } r = parent.random(0.2f, 200); } // resize for better blur compability (prevent crashes) pimg.resize(width / 5, height / 5); pimg.filter(PConstants.BLUR, 9); // create a temp canvas to use te mask canvas = pimg.get(); canvas.filter(PConstants.BLUR, 15); canvas.resize(width / 2, height / 2); // apply mask on the generated image pimg.resize(width / 2, height / 2); pimg.image(canvas, 0, 0); pimg.mask(mask.get()); pimg.endDraw(); // set the transparent image on a black background // save the vignetted image stage.beginDraw(); stage.image(pimg.get(), 0, 0); stage.endDraw(); stage.save(output_path + output_data); }
public void draw() { if (_theOther.get_context().get_regionselected()) { _cur_image = _theOther.get_current_image(); if (_theOther.get_context().get_debug()) _theOther.image(_cur_image, 0, 0); _roi = _theOther.get_context().get_region_of_interest(); _diff_image = _theOther.createImage( _theOther.get_videosource().get_width(), _theOther.get_videosource().get_height(), PConstants.ARGB); _diff_image.copy( _theOther .get_videosource() .diff(Other.get_instance().get_context().get_region_of_interest()), _roi.get_start().get_x(), _roi.get_start().get_y(), _roi.width(), _roi.height(), _roi.get_start().get_x(), _roi.get_start().get_y(), _roi.width(), _roi.height()); _diff_image.filter(PConstants.THRESHOLD, _edgeThreshold / 10f); _diff_image.filter(PConstants.ERODE); for (int i = 1; i < _dilation; i++) { _diff_image.filter(PConstants.DILATE); } if (_theOther.get_context().get_debug()) _theOther.image(_diff_image, 0, _theOther.get_videosource().get_height()); // _edge_image = edges(_theOther.get_current_image()); // _edge_image.filter(PConstants.THRESHOLD, _edgeThreshold/10f); // _theOther.image(_edge_image, 0, 240); _screen = _theOther.get_context().get_screen(); _distance = _theOther.get_context().get_distance(); _blobs = _flob.track(_diff_image); for (int i = 0; i < _blobs.size(); i++) { _tb = _flob.getTrackedBlob(i); if (i == 0 || _screen.distance_to(_tb.cx, _tb.cy) < _distance) { // selectedBlob = tb; _distance = _screen.distance_to(_tb.cx, _tb.cy); } if (_theOther.get_context().get_debug()) { _txt = "id: " + _tb.id + " time: " + _tb.presencetime + " "; _theOther.strokeWeight(1); _theOther.stroke(0, 255, 0); _theOther.fill(220, 220, 255, 100); _theOther.rect(_tb.cx, _tb.cy, _tb.dimx, _tb.dimy); _theOther.fill(0, 255, 0, 200); _theOther.rect(_tb.cx, _tb.cy, 5, 5); _theOther.fill(0); _theOther.line( _tb.cx, _tb.cy, _tb.cx + _tb.velx * _velmult, _tb.cy + _tb.vely * _velmult); _theOther.text(_txt, _tb.cx - _tb.dimx * 0.10f, _tb.cy + 5f); } } _theOther.get_context().set_distance(_distance); // _blobs = _flob.calc(_diff_image); // int numblobs = _blobs.size();//flob.getNumBlobs(); // // for(int i = 0; i < numblobs; i++) { // // ABlob ab = (ABlob)_flob.getABlob(i); // //trackedBlob tb = (trackedBlob)_flob.getTrackedBlob(i); // //now access all blobs fields.. float tb.cx, tb.cy, tb.dimx, tb.dimy... // // // test blob coords here // //b1.test(ab.cx,ab.cy, ab.dimx, ab.dimy); // // //box // drawBlob(ab); // //drawBlob(tb); // } // // ocv.cvOpenCVVideoSource ocv = (OpenCVVideoSource) // _theOther.get_videosource();.threshold(80); // Blob[] blobs = ocv.cv.blobs(10, ocv.get_width()*ocv.get_height()/2, 100, true, // OpenCV.MAX_VERTICES*4); // // // draw blob results // for( int i=0; i<blobs.length; i++ ) { // _theOther.beginShape(); // for( int j=0; j<blobs[i].points.length; j++ ) { // _theOther.vertex( blobs[i].points[j].x, blobs[i].points[j].y ); // } // _theOther.endShape(PConstants.CLOSE); // } if (_theOther.get_context().get_debug()) { _theOther.get_context().get_screen().draw_screen(_theOther); _theOther.get_context().get_region_of_interest().draw(_theOther); _theOther.fill(0, 0, 255); _theOther.text( String.format("edge threshold = %d | dilation = %d", _edgeThreshold, _dilation), 10, 10); } } }