C++ 每行读取灰色图像

C++ 每行读取灰色图像,c++,opencv,C++,Opencv,我有一张灰色的画,画了一条有许多圆圈的线。这些圆圈在右边是地狱色的白色,然后从左边是黑色、白色、黑色等等。 我在C++和OpenCV中做了一个算法,它读取所有的圆并得到颜色。但这是没有效率的。 我想改变我的算法,我不想使用圆或边缘检测的方法。 我喜欢阅读第一行的灰色图像,并在这一行中搜索是否从一侧找到连续的颜色模式白色、黑色、白色、黑色 有人能帮我吗? 谢谢你,我已经用C++和开放的CV制作了一个算法,它可以读取所有的圆并得到颜色。但是这不是有效的。那么,在哪里呢?是的,张贴你的代码和至少你正在

我有一张灰色的画,画了一条有许多圆圈的线。这些圆圈在右边是地狱色的白色,然后从左边是黑色、白色、黑色等等。 我在C++和OpenCV中做了一个算法,它读取所有的圆并得到颜色。但这是没有效率的。 我想改变我的算法,我不想使用圆或边缘检测的方法。 我喜欢阅读第一行的灰色图像,并在这一行中搜索是否从一侧找到连续的颜色模式白色、黑色、白色、黑色

有人能帮我吗?
谢谢你,我已经用C++和开放的CV制作了一个算法,它可以读取所有的圆并得到颜色。但是这不是有效的。那么,在哪里呢?是的,张贴你的代码和至少你正在想的算法的草图将只检测同一行中的白色圆圈。我现在的研究是开发一种算法,从灰色图片中读取依次为黑色、白色和黑色的颜色。也许这会有帮助:
uchar** edge_detect(uchar ** gray_arr,uchar ** binary_arr,int height,int width)
{
int x;
//Store the quickmask as a 3X3 two-d array
short int quickmask[3][3]={{-1, 0, -1},{ 0, 4, 0},{-1, 0, -1} };
for(int i=1;i<(height-1);i++)
{
    for(int j=1;j<(width-1);j++)
    {  
        x=0;
        //Convolute the mask
        for(int a=-1;a<2;a++)
            for(int b=-1;b<2;b++)
                x = x + gray_arr[i+a][j+b]*quickmask[a+1][b+1];
        //Take care of the case wheen x<0 or x>255
        if(x<0) x = 0;
        if(x>255) x = 255;
        if(x<THRESHOLD) x = 0;
        if(x>THRESHOLD) x = 255;
        binary_arr[i][j]=x;
    }
}
return(binary_arr);
}

using namespace cv;


void main()
{
Mat src, src_gray;     

src = imread("lena.jpg");


  uchar * data;
  uchar * * binary_arr;
  uchar * * gray_arr;





   /// Convert it to gray   
  cvtColor( src, src_gray, CV_BGR2GRAY );
 std::cout << src.rows << " --- " << src.cols << std::endl;

Rect myROI(0, src_gray.rows-0.2*src_gray.rows, src.cols, 124);

Mat croppedImage = src_gray(myROI);


 /// Reduce the noise so we avoid false circle detection
  GaussianBlur( croppedImage, croppedImage, Size(9, 9), 2, 2 );

  vector<Vec3f> circles;

  /// Apply the Hough Transform to find the circles
  HoughCircles( croppedImage, circles, CV_HOUGH_GRADIENT, 3, 0.01, 200, 50, 0, 60 );

  /// Draw the circles detected
   for( size_t i = 0; i < circles.size(); i++ )
 {
  Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
  int radius = cvRound(circles[i][2]);
  std::cout << radius << std::endl;
  // circle center
  circle( croppedImage, center, 3, Scalar(0,255,0), -1, 8, 0 );
  // circle outline
  circle( croppedImage, center, radius, Scalar(0,0,255), 3, 8, 0 );
 }

 /// Show your results
 namedWindow( "Hough Circle Transform Demo", CV_NORMAL );
 imshow( "Hough Circle Transform Demo", croppedImage );

 namedWindow( "2", CV_NORMAL );
 imshow( "2", src );

 }`