@fresla wrote:
I am trying to understand the thread channel example but it is a bit confusing as there are some variables that have the same name.
in the ImgAnalysisThread.h file there is a declaration:
ofPixels pixels;
But in the threaded function another ofPixles object is created, also called pixels.
void ImgAnalysisThread::threadedFunction(){ // wait until there's a new frame // this blocks the thread, so it doesn't use // the CPU at all, until a frame arrives. // also receive doesn't allocate or make any copies ofPixels pixels; while(toAnalyze.receive(pixels)){ // we have a new frame, process it, the analysis // here is just a thresholding for the sake of // simplicity pixels.setImageType(OF_IMAGE_GRAYSCALE); for(auto & p: pixels){ if(p > 80) p = 255; else p = 0; } // once processed send the result back to the // main thread. in c++11 we can move it to // avoid a copy #if __cplusplus>=201103 analyzed.send(std::move(pixels)); #else analyzed.send(pixels); #endif } }
As I am trying to build something this makes it hard to understand. Are the references to the object called pixels in the threaded function the local variable declared inside the function or to the variable declared in ImgAnalysisThread.h?
Posts: 1
Participants: 1