Write Mat::frame to stdout and pipe to ffmpeg

Thanks, I tried it but it is not working…

Mat toRgb;
cvtColor(frame, toRgb, COLOR_BGR2RGB);
for (size_t i = 0; i < toRgb.dataend - toRgb.datastart; i++){
       std::cout << toRgb.data[i];
}

The output of ffplay with rgb24 option:


But I find out weird behavior:
My code tree looks like this
├── src
—├── main.cpp
—└── detection
-----└── detection.hpp

the output of the code below works well only if I put it in the main.cpp.
If the code is running inside a class, the output will be as the third picture I sent above.

Im trying to understand why but for now I didn’t find it…
Do you have the same behavior if you write the frame to ouput inside a class ?