Android阈值图像处理

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

原单 原单:

阈: 在这里输入图像描述

    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);
链接地址: http://www.djcxy.com/p/79633.html

上一篇: Android Threshold image processing

下一篇: A good approach for detecting lines in an image?