Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.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

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
Android阈值图像处理_Android_Opencv_Camera_Threshold - Fatal编程技术网

Android阈值图像处理

Android阈值图像处理,android,opencv,camera,threshold,Android,Opencv,Camera,Threshold,这里我有一个使用openCV的代码(算法),用于改进绿板(我们在学校中使用)的图像,过滤噪音并改变黄色和黑色的极性。 我需要在opencv4android上实现,以便使用相机进行实时渲染 原始版本: 阈值: int x,y;//用于阈值化的变量 int a=0;//循环中要使用的变量 整数计数=0;//循环中要使用的变量 //步骤:1使用alpha和beta变量进行简单的亮度和对比度控制 对于(int y=0;y

这里我有一个使用openCV的代码(算法),用于改进绿板(我们在学校中使用)的图像,过滤噪音并改变黄色和黑色的极性。
我需要在opencv4android上实现,以便使用相机进行实时渲染

原始版本:

阈值:

int x,y;//用于阈值化的变量
int a=0;//循环中要使用的变量
整数计数=0;//循环中要使用的变量
//步骤:1使用alpha和beta变量进行简单的亮度和对比度控制
对于(int y=0;y如果(gray_image.at(x,y)你签出OpenCV4Android了吗?是的,在android中实现的代码是不同的,这就是为什么我需要你的帮助在OpenCV4Android中实现它时应该做些什么更改。首先,去掉所有这些循环。有一个内置函数可以找到图像的mean()和threshold()函数,全部可从中获得。如何以黄色和黑色显示阈值?(默认为黑色和白色)-如
rgb.setTo(新标量(253206135),掩码从阈值)
    int x,y; // variables to be used for thresholding

    int a=0;         // variables to be used in loop
    int count=0;     // variables to be used in loop



    //Step: 1 SImple brightness and contrast control using alpha and beta variables
    for( int y = 0; y < image.rows; y++ )
      { for( int x = 0; x < image.cols; x++ )
          { for( int c = 0; c < 3; c++ )
              {
                       image.at<Vec3b>(y,x)[c]                            saturate_cast<uchar>( alpha*( image.at<Vec3b>(y,x)[c] ) + beta );
               }
           }
      }

    // Step: 3 calculating the threshold value using gray scale image
     for( x = 0; x < gray_image.rows; x++ )
     {
       for ( y = 0; y < gray_image.cols; y++ )
       {

        a=a+gray_image.at<uchar>(x,y);
        count=count+1;
       }
     }
     int thresh=0;;
     thresh=a/count;
      printf("%d",thresh); // Calculated the threshold of our image

    // Step:3 Applying the thresholding operation to our image
    for( x = 0; x < image.rows; x++ )
     {
       for ( y = 0; y < image.cols; y++ )
       {
             if(gray_image.at<uchar>(x,y)<thresh)

                      {image.at<cv::Vec3b>(x,y)[0] = 235;  // 0 element is for B component , 1 is for Green component, 2 is for Red component as in openCV BGR is the standard
                       image.at<cv::Vec3b>(x,y)[1] =206;  
                       image.at<cv::Vec3b>(x,y)[2] = 135; } //  below threshold value pixels are assigned whatever colour you decide 
             else


                    {image.at<cv::Vec3b>(x,y)[0] = 0;  
                     image.at<cv::Vec3b>(x,y)[1] = 0;  
                     image.at<cv::Vec3b>(x,y)[2] = 0; }    // above threshold value pixels are assigned this colour
        }
     }


    cv::namedWindow("Final threshold");
    cv::imshow("Final threshold",image);
    imwrite("F:\Threshold image.jpg",image); // saved the image to F drive with name Threshold Image

    waitKey(100);