首页 > 解决方案 > 更改常量 Mat opencv 的值

问题描述

我想将 180 添加到 opencv 中的常量 Mat 中。由于我无法更改常量值,因此我想将其保存到临时垫中,然后将 180 添加到该值中。但是,当我尝试它时,当我打印出这些值时会得到否定的结果。

如果我将 180 添加到 temp 并打印出来,我会得到不需要的输出,即负数。

如果我将 180 添加到 dir ,我会得到正确的值和正数。

我是否为 temp 分配了错误的值?

Mat y(const Mat &image, const Mat &dir) {

  image.copyTo(non_max_sup);
  Mat temp ( dir.size(), CV_32F, Scalar(0));
   dir.copyTo(temp);
  for ( int x = 0; x < dir.rows; x++) {

    for (int y = 0; y < dir.cols; y++) {


        if(dir.at<int>(x,y)<0){

        temp.at<int>(x,y)=  (dir.at<int>(x,y));



            temp.at<int>(x,y)=temp.at<int>(x,y)+180;

            std::cout<<temp.at<float>(x,y)<<std::endl; //wrong numbers
            //std::cout<<dir.at<float>(x,y)+180<<std::endl; correct numbers

        }

}
}


}

标签: c++opencv

解决方案


推荐阅读