Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
opencv java修改像素值 我一直试图在OpenCV java中转换一些OpenCV C++代码,但我好像无法让像素划分正常工作。我取了一个平均移位的分段垫子,我把它转换成灰度,然后转换成32F_Java_Opencv_Image Processing - Fatal编程技术网

opencv java修改像素值 我一直试图在OpenCV java中转换一些OpenCV C++代码,但我好像无法让像素划分正常工作。我取了一个平均移位的分段垫子,我把它转换成灰度,然后转换成32F

opencv java修改像素值 我一直试图在OpenCV java中转换一些OpenCV C++代码,但我好像无法让像素划分正常工作。我取了一个平均移位的分段垫子,我把它转换成灰度,然后转换成32F,java,opencv,image-processing,Java,Opencv,Image Processing,然后,我将最下采样然后上采样的图像(由灰色meanshift mat组成)与原始灰色meanshift mat进行比较 我已经读过了 然而,它和其他类似的东西都不起作用。我收到的错误消息是无效的mat类型5。然而,即使我能看到显著性图,我肯定这是错误的。这是因为当我通过C++中的图像1001.jPG时,我应该看到物体周围的原始图像+红场。在java中,我只看到最后的原始图像 注: AbstractImageProvider.deepCopy(AbstractImageProvider.matTo

然后,我将最下采样然后上采样的图像(由灰色meanshift mat组成)与原始灰色meanshift mat进行比较

我已经读过了

然而,它和其他类似的东西都不起作用。我收到的错误消息是无效的mat类型5。然而,即使我能看到显著性图,我肯定这是错误的。这是因为当我通过C++中的图像1001.jPG时,我应该看到物体周围的原始图像+红场。在java中,我只看到最后的原始图像

注:

AbstractImageProvider.deepCopy(AbstractImageProvider.matToBufferedImage(显著性),disp)

是一个API调用,当我试图显示原始mat、meanShift mat和灰色meanShift mat时,该调用会起作用。它无法表现出显著性

c++

我只做了通道分割,因为我正在测试其他颜色空间,但是在java中我只想使用灰度

  input = MeanShift.clone();
  input.convertTo(input, CV_32F);

  for(int i = 0; i < Pyramid_Size; i++){DS_Pyramid[i] = input.clone();}

  for (int i = 0; i < Pyramid_Size; i++){ 
    for (int k = 0; k <= i; k++){ // Why don't I just downsamplex3 a copy of MeanShift.clone then upsamplex3 that same one? ...
      pyrDown (DS_Pyramid[i], DS_Pyramid[i], Size(DS_Pyramid[i].cols/2, DS_Pyramid[i].rows/2));
      US_Pyramid[i] = DS_Pyramid[i].clone();
    }
    for (int j = 0; j <= i; j++){
      pyrUp (US_Pyramid[i], US_Pyramid[i], Size(US_Pyramid[i].cols*2, US_Pyramid[i].rows*2));
    }
  }

  top = US_Pyramid[Pyramid_Size - 1].clone(); // most down sampled layer, up sampled.
  split(top, top_chs);
  split(input.clone(), meanShift_chs); // split into channels result
  split(input.clone(), sal_chs); // holder to use for compare

  float top_min = 1.0;
  float ms_min = 1.0;
  for (int i = 0; i < top.rows; i++){   // find the smallest value in both top and meanShift
    for (int k = 0; k < top.cols; k++){ // this is so you can sub out the 0 with the min value
      for (int j = 0; j < top.channels(); j++){ // later on
    float a = top_chs[j].at<float>(i,k);
    float b = meanShift_chs[j].at<float>(i,k);
    if (a < top_min && a >= 0) {top_min = a;} // make sure you don't have a top_min of zero... that'd be bad.
    if (b < ms_min && b >= 0)  { ms_min = b;}
      }
    }
  }

  for (int i = 0; i < top.rows; i++){
    for (int k = 0; k < top.cols; k++){
      for (int j = 0; j < top.channels(); j++){
    float a,b,c;
    a = top_chs[j].at<float>(i,k);
    b = meanShift_chs[j].at<float>(i,k);

    if (a <= 0){a = top_min;} // make sure you don't divide by zero
    if (b <= 0){b = ms_min;} // make sure you really don't divide by zero
    if (a <= b){c = 1.0 - a/b;}
    else {c = 1.0 - b/a;}

    // c = sqrt(c); // makes stuff more salient, but makes noise pop out too
    sal_chs[j].at<float>(i,k) = c;
      }
    }
  }
  merge(sal_chs, Saliency); // combine into saliency map
  imshow("saliency", Saliency);
input=MeanShift.clone();
输入。转换到(输入,CV_32F);
对于(inti=0;ifor(int k=0;k在大量搜索后找到了一个简单有效的解决方案。这可能有助于您克服错误-无效的mat类型5

代码:

Mat img = Highgui.imread("Input.jpg"); //Reads image from the file system and puts into matrix
int rows = img.rows(); //Calculates number of rows
int cols = img.cols(); //Calculates number of columns
int ch = img.channels(); //Calculates number of channels (Grayscale: 1, RGB: 3, etc.)

for (int i=0; i<rows; i++)
{
    for (int j=0; j<cols; j++)
    {
        double[] data = img.get(i, j); //Stores element in an array
        for (int k = 0; k < ch; k++) //Runs for the available number of channels
        {
            data[k] = data[k] * 2; //Pixel modification done here
        }
        img.put(i, j, data); //Puts element back into matrix
    }
}
Highgui.imwrite("Output.jpg", img); //Writes image back to the file system using values of the modified matrix
Mat img=Highgui.imread(“Input.jpg”);//从文件系统读取图像并放入矩阵
int rows=img.rows();//计算行数
int cols=img.cols();//计算列数
int ch=img.channels();//计算通道数(灰度:1、RGB:3等)

对于(int i=0;i在大量搜索后找到了一个简单有效的解决方案。这可能有助于您克服错误-无效的mat类型5

代码:

Mat img = Highgui.imread("Input.jpg"); //Reads image from the file system and puts into matrix
int rows = img.rows(); //Calculates number of rows
int cols = img.cols(); //Calculates number of columns
int ch = img.channels(); //Calculates number of channels (Grayscale: 1, RGB: 3, etc.)

for (int i=0; i<rows; i++)
{
    for (int j=0; j<cols; j++)
    {
        double[] data = img.get(i, j); //Stores element in an array
        for (int k = 0; k < ch; k++) //Runs for the available number of channels
        {
            data[k] = data[k] * 2; //Pixel modification done here
        }
        img.put(i, j, data); //Puts element back into matrix
    }
}
Highgui.imwrite("Output.jpg", img); //Writes image back to the file system using values of the modified matrix
Mat img=Highgui.imread(“Input.jpg”);//从文件系统读取图像并放入矩阵
int rows=img.rows();//计算行数
int cols=img.cols();//计算列数
int ch=img.channels();//计算通道数(灰度:1、RGB:3等)

对于(int i=0;i从if(top_temp[k]啊,C++ java C++的错误,我的意思是0。谢谢你,我也得到了大部分java代码现在工作……但是不管什么原因,我在java中得到的斑点都比C++的小。正确的结果如C++所示,结果不正确,如Java所示:“k”在Java代码行中是什么意思?啊,C++ java C++代码,我的错误是我想说的是0。谢谢你指出了这个问题。我也得到了大部分java代码现在的工作……但是不管什么原因,我在java中得到的斑点都比C++的小,正确的结果如C++所示,结果不正确,如Java所示。