{}内声明的变量,只在{}内有效。
uint8_t* in;
std::unique_ptr<uint8_t[]> imgdata;
if(1)
{
/***********************************decode jpg*****************************************/ tensorflow::Env* env = tensorflow::Env::Default();
string jpeg;
ReadFileToStringOrDie(env, s->input_file_name, &jpeg);
const int fsize = jpeg.size();
//printf("fsize = %d\n",fsize);
const uint8* const image_buffer = tensorflow::bit_cast<const uint8_t*>(jpeg.data());
// Try partial decoding (half of the data)
int w, h, c;
//std::unique_ptr<uint8_t[]> imgdata;
tensorflow::jpeg::UncompressFlags flags;
flags.components = 3;
flags.min_acceptable_fraction = 1.0;
imgdata.reset(tensorflow::jpeg::Uncompress(image_buffer, fsize, flags, &w, &h, &c, nullptr));
CHECK(imgdata != nullptr);
image_width = w;
image_height = h;
in = imgdata.get();
printf("image_width = %d\n", image_width);
printf("image_height = %d\n", image_height);
/***********************************decode jpg*****************************************/
}以上代码的运行结果是正确的。
uint8_t* in;
if(1)
{
/***********************************decode jpg*****************************************/
tensorflow::Env* env = tensorflow::Env::Default();
string jpeg;
ReadFileToStringOrDie(env, s->input_file_name, &jpeg);
const int fsize = jpeg.size();
//printf("fsize = %d\n",fsize);
const uint8* const image_buffer = tensorflow::bit_cast<const uint8_t*>(jpeg.data());
// Try partial decoding (half of the data)
int w, h, c;
//std::unique_ptr<uint8_t[]> imgdata;
tensorflow::jpeg::UncompressFlags flags;
flags.components = 3;
std::unique_ptr<uint8_t[]> imgdata;//<-------这里有问题
flags.min_acceptable_fraction = 1.0;
imgdata.reset(tensorflow::jpeg::Uncompress(image_buffer, fsize, flags, &w, &h, &c, nullptr));
CHECK(imgdata != nullptr);
image_width = w;
image_height = h;
in = imgdata.get();
printf("image_width = %d\n", image_width);
printf("image_height = %d\n", image_height);
/***********************************decode jpg*****************************************/
}
以上代码的而结果是错误的