How to get the image pixel at real locations in opencv?

前端 未结 4 2034
臣服心动
臣服心动 2020-12-08 15:49

I want to retrieve the rgb of a pixel in the image. But the location is not integer location but real values (x,y). I want a bilinear interpolated value. How could

4条回答
  •  感情败类
    2020-12-08 16:23

    bilinear interpolation just means weighting the value based on the 4 nearest pixels to the one you are examining. The weights can be calculated as follows.

    cv::Point2f current_pos; //assuming current_pos is where you are in the image
    
    //bilinear interpolation
    float dx = current_pos.x-(int)current_pos.x;
    float dy = current_pos.y-(int)current_pos.y;
    
    float weight_tl = (1.0 - dx) * (1.0 - dy);
    float weight_tr = (dx)       * (1.0 - dy);
    float weight_bl = (1.0 - dx) * (dy);
    float weight_br = (dx)       * (dy);
    

    Your final value is calculated as the sum of the products of each pixel with its respective weight

提交回复
热议问题