所以我找到了可以获得BGR像素值的代码。
ofstream newFile("scorefile.txt", std::ios_base::app); //this is mine
uint8_t* pixelPtr = (uint8_t*)frame2.data;
int cn = frame2.channels();
Scalar_<uint8_t> bgrPixel;
for (int i = 0; i < frame2.rows; i++)
{
for (int j = 0; j < frame2.cols; j++)
{
bgrPixel.val[0] = pixelPtr[i*frame2.cols*cn + j*cn + 0]; // B
bgrPixel.val[1] = pixelPtr[i*frame2.cols*cn + j*cn + 1]; // G
bgrPixel.val[2] = pixelPtr[i*frame2.cols*cn + j*cn + 2]; // R
newFile << "B: " << bgrPixel.val[0] << " G: " << bgrPixel.val[1] << " R: " << bgrPixel.val[2] << "\n"; //this is mine
// do something with BGR values...
}
}
但是在数字中获取值时,这些数字会转换为ascii符号,如
姓名|价值|型
bgrPixel.val [0] | 64&#39; @&#39; | unsigned char
我该怎么做才能将它们保存为数字?