我能够通过将 uint8 数据转换为字节(下面的代码)来获得视频流,但它看起来像静态的。我认为我的位图标题有问题(我认为它丢失了)。有人可以告诉我是否可以从我收到的位图标题的原始数据中包含任何内容?
有关我收到的消息的信息:http: //docs.ros.org/melodic/api/sensor_msgs/html/msg/Image.html
接收到的示例原始图像数据:
{encoding: bgr8, height: 480, header: {stamp: {secs: 1599095871, nsecs: 933816910}, frame_id: bottom_camera_front, seq: 4766}, step: 1920, data:gnZ8gnZ8gnZ8gnZ8gXZ5gXZ5f3V7f3V7fXZ7fXZ7fHR7fXV8fXV/fnaAfXV/e3Z/eXd9d3d9d3d9d3d9eXd9eXd9e3d9e3d9fXZ9fXZ9fnZ9fnZ9fnZ9fnZ9gHV9fnZ9fXl/enh+enh+enh+eXd9eHZ8enh+fXuBfHqAe3l/fXl/fHh+fnd+fnd+gHh/gHh/hHmBhHmBgnqBgnqBgXqBgXqBfHqAfHqAenqAe3uBe3uBe3uBeXyBen2Cen2CfHyCfXuBf3uBf3uBf3uBf3uBf3uBf3uBf3uBgHyCgHyCgHyCgHyCgHyCgHyCgHyCgHyCgnuCgnuCgHyCgHyCfnyCfnyCe3qDe3qDd3qCd3qCdXqDdnuEdHuEdHuEcnuEcnuEdHyDdHyDdnyDdnyDeHuDeXuDeXuDe3qDfXqDfHmCfHmCfHmCfHmCfHmCfHmCfXqDeXqEenuFe3yGfH2HfH6GfX+HfX+HfX+HfH+EfH+EfH+EfH+Ee36De36De36Ce36Cfn6Efn6Ef3+Ff3+FgIGFf4CEfYCEfH+ DfH+De36Ce36CfH+DfH+Ee36Den2CfX2Df3+FgX+FgX+FgX+FgX+FgX+Ff3+Ff3+Ff3+Ff3+Ff3+Ff3+FfYCFfYCFfYCFfYCFfIGEfIGEfIGEfIGEeoGEeoGEeoCFe4GGe4GGfYGGfYGGgICGgICGgoCGhICGhICGh3+Jhn6IhH+IhH+Ig36HhH+IgoCGgoCGgX+FgX+Fg3+EhICFhYGGhYGGiIKHiYKHiYGIi4CIi4CIi4CIi4CIi4CIiYKHiYKHioOIioOIiIOFiIOFiIOFiIOFiYSGiYOIh4CHh3+Jh4CHhn+Gh4CHh4CHiYGIioKJi4SJi4SJioOIio
Widget _buildVideoOutput(snapshot) {
if (!snapshot.hasData) {
return Text("");
}
var msg = snapshot.data;
// print(msg);
var rawDataString = msg["data"]; //uint8 string (bgr8)
// print(rawDataString);
var secs = msg["header"]["stamp"]["secs"];
// print(secs); //time in secs
List<int> bytes = utf8.encode(rawDataString); //convert data to bytes
// print(bytes);
Uint8List dataInts = Uint8List.fromList(bytes);
// print(dataInts);
int imageWidth = 640;
int imageHeight = 480;
Bitmap bitmap = Bitmap.fromHeadless(imageWidth, imageHeight, dataInts);
// Bitmap brightBitmap = bmp.brightness(bitmap, 0.2);
// Bitmap nowThisBitmapLooksWeird = bmp.contrast(brightBitmap, 1.5);
// Bitmap finalBitmap =
// bmp.adjustColor(nowThisBitmapLooksWeird, saturation: 1.0);
Uint8List headedBitmap = bitmap.buildHeaded();
//ui.Image outputImage = await bitmap.buildImage();
//canvas.drawImage(outputImage, Offset.zero, ui.Paint());
Image image = Image.memory(
headedBitmap,
fit: BoxFit.none,
);
return image;
}