Ask Your Question

bjarne's profile - activity

2020-06-05 18:39:47 -0600 received badge  Popular Question (source)
2014-09-09 02:55:25 -0600 received badge  Scholar (source)
2014-09-09 02:55:23 -0600 received badge  Supporter (source)
2014-09-07 08:05:44 -0600 commented question Save box parameter in an array

hej berak...thanks for your reply... sorry but my programming knowledge is very poor, so I don't know exactly what you mean or how to make it.

2014-09-07 04:44:26 -0600 asked a question Save box parameter in an array

Hej, I want to classify an image with circle objects. Before classification I use contourising and fitellipse. For the classification I want to save the box parameters (size, angle, center) in an array. But when I test with std::cout the saved data, I get different values. I don't know what I'm doing wrong. Anybody have an idea? Thanks in advance!

cv::Mat image = cv::imread(argv[1],1);
if (!image.data)
    return 0;


cv::Mat grayImage;
cv::cvtColor( image, grayImage, CV_BGR2GRAY );
cv::blur( grayImage, grayImage, cv::Size(3,3) );

cv::vector<cv::vector<cv::Point> > contours;
cv::Mat bimage = grayImage >= 40;

findContours(bimage, contours, CV_RETR_LIST, CV_CHAIN_APPROX_NONE);
cv::Mat cimage = cv::Mat::zeros(bimage.size(), CV_8UC3);

int countEllipses = 8;
float koord[countEllipses][5];  
double maxWidth;
double minWidth;


    for(size_t i = 0; i < contours.size(); i++)
    {
    size_t count = contours[i].size();
    if( count < 6 )
        continue;

    cv::Mat pointsf;
    cv::Mat(contours[i]).convertTo(pointsf, CV_32F);
    cv::RotatedRect box = fitEllipse(pointsf);

    if( MAX(box.size.width, box.size.height) > MIN(box.size.width, box.size.height)*1.5 )
        continue;

    cv::drawContours(cimage, contours, (int)i, cv::Scalar::all(255), 1, 8);

    cv::ellipse(image, box, cv::Scalar(0,0,255), 1, CV_AA);
    cv::ellipse(image, box.center, box.size*0.5f, box.angle, 0, 360, cv::Scalar(0,255,255), 1, CV_AA);

    float x = box.center.x;
    float y = box.center.y;
    float height = box.size.height;
    float width = box.size.width;

    std::cout << "Mittelpunkt " << box.center << std::endl;
    std::cout << "Winkel " << box.angle << std::endl;
    std::cout << "Größe " << box.size << std::endl;
    std::cout << "Anzahl " << i << std::endl;
    std::cout << "Test Breite " << box.size.width << std::endl;
    std::cout << "Test Höhe " << box.size.height << std::endl;
    countEllipses = i;

    koord[i][0] = x;
    koord[i][1] = y;
    koord[i][2] = (float)box.angle;
    koord[i][4] = height;
    koord[i][5] = width;

    if(koord[i][5] > maxWidth){
        maxWidth = koord[i][5];
            }
    if(box.size.width < minWidth){
               minWidth = box.size.width;
    }


    cv::Point2f vtx[4];
    box.points(vtx);
    for( int j = 0; j < 4; j++ ) {

        cv::line(cimage, vtx[j], vtx[(j+1)%4], cv::Scalar(0,255,0), 1, CV_AA);}

}

for (int k = 0; k < countEllipses; k++ )
{
    std::cout.precision(6);
    std::cout << "------ Objekt "<< k <<" ---------" << std::endl;
    std::cout << "Mittelpunkt x: " << koord[k][0] << std::endl;
    std::cout << "Mittelpunkt y: " <<koord[k][1] << std::endl;
    std::cout << "Winkel: " << koord[k][2] << std::endl;
    std::cout << "Box Höhe: " << koord[k][3] << std::endl;
    std::cout << "Box Breite: " <<koord[k][4] << std::endl;
}
std::cout << "Größte Breite: " << maxWidth << std::endl;
std::cout << "Kleinste Breite: " << minWidth << std::endl;
2014-07-16 08:38:41 -0600 received badge  Editor (source)
2014-07-16 07:12:51 -0600 received badge  Student (source)
2014-07-16 06:09:05 -0600 asked a question drawing ellipse sectors problem (siemensstar)

Hej guys, I have to draw a siemens star in opencv and c++. I use the ellipse() function to draw the sectors. The code works, but when I choose an amount for the arcs that produce decimal angles, the sectors will be drawn irregular, though the angles are calculated correctly.

int main(int argc, char** argv) {
int sie_anz = 50;       // number of arcs
float pp_inch = 300;
float sie_d_cm = 5;     // diameter

int u_anz, v_anz;
u_anz = round((pp_inch * sie_d_cm) / 2.54); // Inch/Pixel
v_anz = u_anz;
float segAnf, segEnd;

Mat siemensstar(v_anz + 50, u_anz + 50, CV_8UC1, 255);

Point sie_mp(v_anz / 2 + 25, u_anz / 2 + 25);
float winkel = 360.0f / (2 * sie_anz);
for (float i = 0.0f; i < 360.0f; i += 2 * winkel )

{

    ellipse(siemensstar, sie_mp, Size(u_anz / 2, u_anz / 2), 0, (double)i,
            (double)(i+ winkel), Scalar(0), -1, CV_AA);
    segAnf= i;
    segEnd= i + winkel;
    cout << "Sector angle start = " << segAnf << "  sector angle end = " << segEnd <<  endl;
}
imshow("Siemensstern", siemensstar);
waitKey(0); }

I have got these angle values for 50 arcs:

Sector angle start = 0 sector angle end = 3.6
Sector angle start = 7.2 sector angle end = 10.8
Sector angle start = 14.4 sector angle end = 18
Sector angle start = 21.6 sector angle end = 25.2
Sector angle start = 28.8 sector angle end = 32.4
Sector angle start = 36 sector angle end = 39.6
Sector angle start = 43.2 sector angle end = 46.8
Sector angle start = 50.4 sector angle end = 54
Sector angle start = 57.6 sector angle end = 61.2
Sector angle start = 64.8 sector angle end = 68.4
Sector angle start = 72 sector angle end = 75.6
Sector angle start = 79.2 sector angle end = 82.8
Sector angle start = 86.4 sector angle end = 90
Sector angle start = 93.6 sector angle end = 97.2
and so on..

The sectors have all the same size, but the star looks like that:

image description

Someone have an idea what I do wrong? Thanks a lot!!

2014-07-01 08:45:39 -0600 commented answer mode value

Hej Witek, thanks for your answer, but I think that the maxVal and Mode Value are not the same. When I use your approach, I will get the highest bin-value but not the amount of pixels for this bin

2014-07-01 02:18:00 -0600 asked a question mode value

Hey..I'm new in opencv and have to compute the mode value of an grayscale image in opencv and c++. I have searched the internet for examples, but havnt found. Anyone have an idea how can i make it? Thank you!!