I asked this question at stackoverflow but didn't get an answer.
I'm trying to write pixel values of an image in RGB to a file with Opencv. Basically file will be made of values like
R-G-B
125-12-54
4-47-203
There is nothing wrong with the image, display program shows it without any problems. Here's the relevant portion of the code.
Mat rawData = Mat(1, elementcount, CV_8UC1, UArray);
image = imdecode(rawData, IMREAD_COLOR);
...
for (int i = 0; i < rows; i++){
for (int t = 0; t < cols; t++){
Vec3b intensity = image.at<Vec3b>(rows, cols);
ImageValueToString(intensity);
I've tried the following but everytime the program crashes
void ImageValueToString(Vec3b imagevalue){
int blue = imagevalue.val[0];
string blue_string = to_string(blue); // Crash
void ImageValueToString(Vec3b imagevalue){
int blue = static_cast<int>(imagevalue.val[0]);
string blue_string = to_string(blue); // Crash
void ImageValueToString(Vec3b imagevalue){
uchar blue = imagevalue.val[0];
int blue_int = (int)blue;
string blue_string = to_string(blue_int); // Crash
void ImageValueToString(Vec3b imagevalue){
int blue = imagevalue.val[0];
string s;
stringstream out;
out << blue;
s = out.str(); // crash
The program works if I omit string conversion. This works
int red = 5;
string red_string = to_string(red);
But when converted from uchar, int to string conversion doesn't work. I'm baffled. Any suggestions? I must be missing something trival.