We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Dear team,
I have an issue regarding the following: I use opencv to perform a first analysis of a video. I also use Daniel S. code on computer vision to analyse pixels.
I would like to take further actions on the processed videodata/frames (generated in draw() by opencv, though it keeps using the original video as input. What is the correct way to use the opencv generated data in draw (the drawed contours + created background) as input for further analysis?
import gab.opencv.*; import processing.video.*; Movie video; OpenCV opencv; ////////////////////new code int blobCounter = 0; int framecount= 0; int maxLife = 50; color trackColor; float threshold = 100; float distThreshold = 50; // the treshold for making a new blob if treshold (distance of pixels) is too big ////////////////////end new code void setup() { size(480, 360); video = new Movie(this, "drukke_straat.mp4"); // drukke straat opencv = new OpenCV(this, width, height); opencv.startBackgroundSubtraction(20, 3, 0.5); video.loop(); video.play(); } void draw() { if(video.width > 0 && video.height > 0){//check if the cam instance has loaded pixels else do nothing //frameRate(25); //image(video, 0, 0); background(0); opencv.loadImage(video); opencv.updateBackground(); opencv.dilate(); opencv.erode(); for (Contour contour : opencv.findContours()) { fill(255,0,0); strokeWeight(1); stroke(255, 0, 0); contour.draw(); } } // saveFrame("output2/frames"+framecount+".png"); framecount ++ ; } void movieEvent(Movie m) { m.read(); }
bellow code is the code that uses video as input. I am not sure how to correctly feed the bellow code with the opencv generated data. Currently I have two scripts sepperatly , furst i run opencv scipt and save all the frames, then i make an mp4 file with moviemaker. after it i use it on the second scipt. Some advice would be appreciated.
void draw() { if(video.width > 0 && video.height > 0){//check if the cam instance has loaded pixels else do nothing frameRate(8); image(video, 0, 0); //background(0); ArrayList<Blob> currentBlobs = new ArrayList<Blob>(); // new array is created previous current array is cleared // Begin loop to walk through every pixel for (int x = 0; x < video.width; x++ ) { for (int y = 0; y < video.height; y++ ) { int loc = x + y * video.width; // What is current color color currentColor = video.pixels[loc]; float r1 = red(currentColor); float g1 = green(currentColor); float b1 = blue(currentColor); float r2 = red(trackColor); float g2 = green(trackColor); float b2 = blue(trackColor); float d = distSq(r1, g1, b1, r2, g2, b2); if (d < threshold*threshold) { // treshold* treshhold as d is operated in the same way (squared)
Answers
please format the code properly.
undo the current formatting. highlight the code, press ctrl-o.
as requested
A way would be to save the frame as an image and read the image each time , though it is taxing to keep writing the image and read it back in to feed it into the second code. Can i create a snapshot and without writing it as a .png feed it ? Not sure what the sensible way would be.
https://Processing.org/reference/PImage_get_.html
Dear GoToLoop, will study the advice 1st thing tomorrow. thank you for the hint
GoToLoop, thank you for pointing on the reference.
using: PImage cc= get(0,0,width,height);
helped me to solve my issue.