Ask Your Question

Revision history [back]

I think you can use lineiterator :

for (int i=0;i <contour.size();i++)
      drawContours( drawing1, contours, i, Scalar(i+1), 1 ); // contour.size() must be less than 254
cv::LineIterator it(drawing1, Point(0,10),Point(600,300), 4);
cv::LineIterator it2 = it;
vector <int> carCounter(contours.size()); // 

for (int i=0;i <carCounter.size();i++)
     carCounter[i]=0;
for(int nbPt = 0; nbPt < it.count; nbPt++, ++it)
{
    if (drawing1.at<uchar>(it.pos()) != 0)
    {
        carCounter[i]++;
    }
}

PS I haven't check this program

I think you can use lineiterator :(may be there is another way to count car)

for (int i=0;i <contour.size();i++)
      drawContours( drawing1, contours, i, Scalar(i+1), 1 ); // contour.size() must be less than 254
cv::LineIterator it(drawing1, Point(0,10),Point(600,300), 4);
cv::LineIterator it2 = it;
vector <int> carCounter(contours.size()); // 

for (int i=0;i <carCounter.size();i++)
     carCounter[i]=0;
for(int nbPt = 0; nbPt < it.count; nbPt++, ++it)
{
    if (drawing1.at<uchar>(it.pos()) != 0)
    {
        carCounter[i]++;
    }
}

PS I haven't check this program

I think you can use lineiterator (may be there is another way to count car)

for (int i=0;i <contour.size();i++)
      drawContours( drawing1, contours, i, Scalar(i+1), 1 ); // contour.size() must be less than 254
cv::LineIterator it(drawing1, Point(0,10),Point(600,300), 4);
cv::LineIterator it2 = it;
vector <int> carCounter(contours.size()); // 

for (int i=0;i <carCounter.size();i++)
     carCounter[i]=0;
for(int nbPt = 0; nbPt < it.count; nbPt++, ++it)
{
    if (drawing1.at<uchar>(it.pos()) != 0)
    {
        carCounter[i]++;
    }
}

in carCounter number nonzero values is equal to number of car which shapes crossed the red line...

PS I haven't check this program

I think you can use lineiterator (may be there is another way to count car)

for (int i=0;i <contour.size();i++)
      drawContours( drawing1, contours, i, Scalar(i+1), 1 ); // contour.size() must be less than 254
cv::LineIterator it(drawing1, Point(0,10),Point(600,300), 4);
cv::LineIterator it2 = it;
vector <int> carCounter(contours.size()); // 

for (int i=0;i <carCounter.size();i++)
     carCounter[i]=0;
for(int nbPt = 0; nbPt < it.count; nbPt++, ++it)
{
    if (drawing1.at<uchar>(it.pos()) != 0)
    {
        carCounter[i]++;
    }
}
int nbCar=0;
for (int i=0;i<carCounter.size();i++)
     if (carCounter[i]!=0)
          nbCar++;
cout<<nbCar << "cross line\n";

in carCounter number nonzero values is equal to number of car which shapes crossed the red line...

PS I haven't check this program