标题:(请高手指教) 如何用C语言读取bmp图片中的r,g,b分量?
只看楼主
nofailure
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-5-17
 问题点数:0 回复次数:0 
(请高手指教) 如何用C语言读取bmp图片中的r,g,b分量?
下面这段是一个利用机器人仿真工具自带的API: wb_camera_get_image() 获取仿真过程的图片,该API特点是图片像素点以三位r,g,b保存,接着即可以用wb_camera_image_get_red,  wb_camera_image_get_blue,  wb_camera_image_get_green等获取r,g,b分量。
现在将wb_camera_get_image() 获取到的图片送另一matlab程序处理后得到了一个bmp格式的局部图。该局部图希望再送给机器人的C语言控制程序进行r,g,b分量的提取和分析,这貌似不像wb_camera_image_get_red这么简单,请问该如何实现?盼请高手解答!感谢!

image = wb_camera_get_image(camera0);  /*wb_camera_get_image为仿真工具本身的API*/

    wb_camera_get_image(camera1);

    if (pause_counter == 0) {
      red = 0;
      green = 0;
      blue = 0;

      /*
       * Here we analyse the image from the camera. The goal is to detect a
       * blob (a spot of color) of a defined color in the middle of our
       * screen.
       * In order to achieve that we simply parse the image pixel after
       * pixel and we sum for each color its value. We weight this value by
       * the distance of the current pixel to the center of the image so that
       * the blob will get a higher score if it is centered.
       */
      for (i = 0; i < width0; i++) {
        centering_weight = (i < (width0 / 2)) ? i - 10 : (width0 - i - 10);
        /* We read only the lower part of the image to avoid the sky. */
        for (j = (height0 / 2); j < height0; j++) {
          red += wb_camera_image_get_red(image, width0, i, j) * centering_weight;
          blue += wb_camera_image_get_blue(image, width0, i, j) * centering_weight;
          green += wb_camera_image_get_green(image, width0, i, j) * centering_weight;
        }
      }
    /*if blue, turn left.*/
         if (blue >= COLOR_BLOB_VALUE) {
              printf("Looks like I found a blue blob ! Turn Left!\n");
              pause_counter = 50;
              left_speed = -SPEED;
              right_speed = -SPEED / 2;
              
          } else
         ……


[ 本帖最后由 nofailure 于 2010-5-17 21:51 编辑 ]
搜索更多相关主题的帖子: C语言 bmp 分量 指教 
2010-05-17 21:44



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-307095-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.176108 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved