Ask Your Question

vsay's profile - activity

2019-08-18 05:01:03 -0600 received badge  Famous Question (source)
2019-06-12 06:22:02 -0600 received badge  Popular Question (source)
2017-10-26 09:48:05 -0600 received badge  Popular Question (source)
2017-04-04 08:12:20 -0600 received badge  Notable Question (source)
2016-12-30 23:10:18 -0600 received badge  Notable Question (source)
2016-03-02 03:41:33 -0600 received badge  Popular Question (source)
2015-11-30 08:46:54 -0600 received badge  Popular Question (source)
2014-02-28 03:23:26 -0600 asked a question Analyse features of the connected components with histogram with opencv and c++

Hi,

I found many example working histogram in opencv, but they are mostly working on images.

For my case, I found each connected components in my image. From these connected components, I calculated their area(); boundingbox(); density(); Thus, I stored value of each features (area, height and density) in each array (arr_area, arr_height, arr_density).

I want to analyse those features in histogram

  • What are the most populated area in the histogram?
  • How many connected components in certain areas?
  • ....

So I believe histogram can show all these information.

How can I build these histograms in opencv c++? I.e :

  • In Histogram area : x = number of area, and y is number of cc
  • In Histogram height: x = number of height, and y is number of cc
  • In Histogram density: x = number of density, and y is number of cc

Thank

2014-02-25 04:35:35 -0600 asked a question Effecient ways to merge blob whose position inside another blob using cvbloblib

I basically want to remove all blobs whose positions insides another blobs.

image description

I use the cvbloblib . I can get all the blobs; however, the library basically detect all blob even the position of those blob inside another.

I think of using iterative ways to detect if each blob inside another and merge them together.

for (int i = 0; i<res.GetNumBlobs(); i++){
       for (int j = 0; i<res.GetNumBlobs(); i++){
              //find if each blob is inside another
              if(condition blob(i) inside){
                       //delete
                       //break or return to another blob(i+1)
              }
       }
 }

However there are some issues :

  1. iterative ways is not effecient way

  2. You see in the image above, there are the cases where a blobs insides not 1 but could be another N blobs. so I tend to think about recursive function to do that.

Do you have any ways to merge those blobs inside ?

2014-02-21 08:43:10 -0600 asked a question How to use clustering with opencv c++ to classify the connected component based on the area and height

Hi, with opencv c++, I want to do clustering to classify the connected components based on the area and height. I do understand the concept of the clustering but i have hard time to implement it in opencv c++.

In the opencv

http://docs.opencv.org/modules/core/doc/clustering.html

There is a clustering methods kmeans

Most of the website I searched, they just explain the concept and parameters of the kmeans function in opencv c++ and most of them were copied from the opencv document website.

double kmeans(InputArray data, int K, InputOutputArray bestLabels, TermCriteria criteria, int attempts, int flags, OutputArray centers=noArray() )

There is also good example here but it was implemented in Python

http://docs.opencv.org/trunk/doc/py_tutorials/py_ml/py_kmeans/py_kmeans_opencv/py_kmeans_opencv.html?highlight=kmeans

As i mentioned above, I have all the connected components and i can calculate areas and height of each connect components.

I want to use clustering to distinguish between connected components.

For instance, with k-means methods i would use k=2.

Thank..

2014-02-20 06:46:09 -0600 commented answer How to link opencv and other dll files to output exe of visual studio 2013

thank @tuannhtn could you describe the steps from scratch ? I am new with cmake, opencv and c++ ... All i know is in vs2013 after we compile the project we could get the exe file. i download opencv2.4.7.2.exe i install it and put in c:/opencv and when i create the project in vs2013 i just configure the path of linker and dependencies.

2014-02-18 09:12:24 -0600 commented answer Error Exception Handling For Cv::Rect opencv in C++

The last two check, i tried to avoid the error when i increase the width and heigth of the rect where the component are too near to the border For the component at the most right near the border if I increase the width it will be error. The same thing for the height in case the component is at the bottom near the border

2014-02-17 10:20:11 -0600 asked a question Error Exception Handling For Cv::Rect opencv in C++

I have bounding box and I want to crop image with this bounding box.

However I want to increase the size of the bounding box, so I do

                if ((roi_.x - 5) > 0) // i test here in case the component at the left near border 
//we do not minus otherwise it will be error
                {
                    roi_.x += (-5);
                }
                if ((roi_.y - 5) > 0) // i test here in case the component at the left near border 
//we do not minus otherwise it will be error
                {
                    roi_.y += (-5);
                }
                if (&(roi_ + cv::Size(10, 0)) != NULL)
                {
                    roi_.width += 10;
                }
                if (&(roi_ + cv::Size(0, 10)) != NULL)
                {
                    roi_.height += 10;
                }

For the component at the most right near the border if I increase the width it will be error. The same thing for the height in case the component is at the bottom near the border

Are there any ways to handle this exception?

2014-02-17 09:25:49 -0600 commented answer Remove black border lines around image after scan with opencv c++

well, 4 nested loops will affect my program's performances

2014-02-17 03:03:25 -0600 asked a question Remove black border lines around image after scan with opencv c++

I have tiff images. After scan those images, there are long black lines around the the borders.

I manualy crop the image with increase x += 50; y += 50; width -= 100; heigth -= 100

With above approache, I can crop the images.

I want to ask if there is any way i could remove it autometically without tunning the parameters of x, y, width and heigth such as image enhancement?

Thank

EDITED

  • The image is grayscale image
  • There is only black and white color in the image so basically i would like to replace those black color with whit color
  • After scan the image there are long black pixel at the borders of the image and i want to remove that
2014-02-13 08:47:12 -0600 commented question How to link opencv and other dll files to output exe of visual studio 2013

@GilLevi I tried to copy dll put the same location as my exe files but it not works

2014-02-13 07:06:53 -0600 asked a question How to link opencv and other dll files to output exe of visual studio 2013

I am new with visual studio, opencv.

I am using visual studio 2013, opencv and c++ for my project.

I configured (copied path) the opencv and other library to my computer environment system.

After run the project in visual studio, normally, there will be an exe file in the project.

I can copy the exe file in the project folder and copy to other place in my computer and it will run normally.

This is because my computer environment systems are configured with opencv and other library.

I want to do the same thing with other computers BUT I do not want to manually configure each computer with opencv and other libraries.

Are there any ways that I can do to link everythings all in exe file after run the project in visual studio 2013 so that I can run the exe without depend on the path of libaries and opencv?

Thank you.

2014-02-11 02:36:10 -0600 commented answer Implementation Run Length Smoothing Algorithm in C++

@Luca Thank you, i already fix the issue, Just like you said I have some problems with indexs. However, I still not satify with the implementation since I only use nested loop rather than access in matrice way. what you think?

2014-02-07 09:17:40 -0600 commented answer Using colone Matlab in c++ opencv Mat Structure

@Guanta you are right, I edited the C++ code I want to write c++ code to do the same thing as this matlab code tmpImg(i,j-one_count:j-1)=0;

2014-02-07 08:40:09 -0600 received badge  Student (source)
2014-02-07 06:50:21 -0600 commented answer Using colone Matlab in c++ opencv Mat Structure

Thank, @Guanta, i edited the question please have a look

2014-02-06 09:59:40 -0600 commented answer Using colone Matlab in c++ opencv Mat Structure

Error C2039: 'setTo' : is not a member of 'cv::Range'

2014-02-06 09:35:40 -0600 commented answer Using colone Matlab in c++ opencv Mat Structure

Thank, I upload my whole code in new question where there are both Matlab and C++ http://answers.opencv.org/question/27866/implementation-run-length-smoothing-algorithm-in-c/

2014-02-06 09:29:49 -0600 asked a question Implementation Run Length Smoothing Algorithm in C++

This is my old question related to RLSA in C++, but I havent got any help yet.

I tried to implement the code from Matlab to C++

The description of this algorithm :

http://crblpocr.blogspot.fr/2007/06/run-length-smoothing-algorithm-rlsa.html http://crblpocr.blogspot.fr/2007/06/determination-of-run-length-smoothing.html

There is RLSA implementation in Matlab by this thread :

http://mathworks.cn/matlabcentral/newsreader/view_thread/318198

MatLabCode

 hor_thresh=20;
zeros_count=0;
one_flag=0;
hor_image=image;
for i=1:m
    for j=1:n
        if(image(i,j)==1)
            if(one_flag==1)
                if(zeros_count<=hor_thresh)
                    hor_image(i,j-zeros_count:j-1)=1;
                else
                    one_flag=0;
                end
                zeros_count=0;
            end
            one_flag=1;
        else 
            if(one_flag==1)
                zeros_count=zeros_count+1;
            end
        end
    end
end

I tried to implement in C++ Code

    int hor_thres = 22;
                int one_count = 0;
                int zero_flag = 0;
                Mat tmpImg = Mat(Img.size(), CV_8UC1, Scalar(0, 0, 0));
                for (int j = 0; j<Img.rows; j++){
                    for (int i = 0; i<Img.cols; j++){
                        if (Img.at<uchar>(j, i) == 0)
                        {
                            if (zero_flag == 1)
                            {
                                if (one_count <= hor_thres)
                                {           
                                    tmpText(cv::Range(j - zero_count, j), cv::Range(i, i+1)).setTo(cv::Scalar::all(255));
// I want to do the same thing in Matlab as this  image(i,j-one_count:j-1)=0;
                                }
                                else
                                {
                                    zero_flag = 1;
                                }
                                one_count = 0;
                            }
                            zero_flag = 1;
                        }
                        else
                        {
                            if (zero_flag == 1)
                            {
                                one_count = one_count + 1;
                            }
                        }
                    }
                }

This time no error but the result is not expected ..

The issue is the way i want to write c++ code the same thing as

Matlab

tmpImg(i,j-one_count:j-1)=0;

C++

tmpText(cv::Range(j - zero_count, j), cv::Range(i, i+1)).setTo(cv::Scalar::all(255));

Anyidea???

Another thing is in Matlab the index start from 1 while C++ start from 0.

Thank

2014-02-06 09:06:57 -0600 asked a question Using colone Matlab in c++ opencv Mat Structure

Hi everyone,

Are there any ways in c++ I can access Mat structure like colon in Matlab.

in Matlab

image(i,j-one_count:j-1)=0;

how can I write the same thing in C++?

EDIT

According to Running length smoothing algorithm The whole code

MatLabCode

  hor_thresh=20;
zeros_count=0;
one_flag=0;
hor_image=image;
for i=1:m
    for j=1:n
        if(image(i,j)==1)
            if(one_flag==1)
                if(zeros_count<=hor_thresh)
                    hor_image(i,j-zeros_count:j-1)=1;
                else
                    one_flag=0;
                end
                zeros_count=0;
            end
            one_flag=1;
        else 
            if(one_flag==1)
                zeros_count=zeros_count+1;
            end
        end
    end
end

I tried to implement in C++ Code

                int hor_thres = 22;
                int one_count = 0;
                int zero_flag = 0;
                Mat tmpImg = Mat(Img.size(), CV_8UC1, Scalar(0, 0, 0));
                for (int j = 0; j<Img.rows; j++){
                    for (int i = 0; i<Img.cols; j++){
                        if (Img.at<uchar>(j, i) == 0)
                        {
                            if (zero_flag == 1)
                            {
                                if (one_count <= hor_thres)
                                {           
                                    tmpText(cv::Range(j - zero_count, j), cv::Range(i, i+1)).setTo(cv::Scalar::all(255));
// I want to do the same thing in Matlab as this  image(i,j-one_count:j-1)=0;
                                }
                                else
                                {
                                    zero_flag = 1;
                                }
                                one_count = 0;
                            }
                            zero_flag = 1;
                        }
                        else
                        {
                            if (zero_flag == 1)
                            {
                                one_count = one_count + 1;
                            }
                        }
                    }
                }

This time no error but the result is not expected ..

The issue is the way i want to write c++ code the same thing as

Matlab

tmpImg(i,j-one_count:j-1)=0;

C++

tmpText(cv::Range(j - zero_count, j), cv::Range(i, i+1)).setTo(cv::Scalar::all(255));

Anyidea???

Thank

2014-02-05 07:07:12 -0600 commented question Implementation Run Length Smoothing Algorithm in C++

@Guanta thank for your advice, frankly speaking I could convert the second program to c++ but it takes a bit long since it uses the nested loop that I do not want. For the first program on the other hand, it manipulate the image in vector ways and since I am new with opencv and c++ that is why I think maybe those who are expert in these fields could help

2014-02-04 08:01:28 -0600 asked a question Implementation Run Length Smoothing Algorithm in C++

I am new with C++ and OpenCV.

I came across an interesting article:

http://crblpocr.blogspot.fr/2007/06/run-length-smoothing-algorithm-rlsa.html http://crblpocr.blogspot.fr/2007/06/determination-of-run-length-smoothing.html

There is RLSA implementation in Matlab by this thread :

http://mathworks.cn/matlabcentral/newsreader/view_thread/318198

In link above : Matlab Code Vector Version by Bruno Luong

% Data
x=[0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 1 0 0 0 0 0 0 0 1 1 0 0 0;
  0 0 0 1 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 1 0 0 0 0 0 1 0 0 0]
C = 4;
% Engine
[m n] = size(x);
xx = [ones(m,1) x ones(m,1)];
xx = reshape(xx',1,[]);
d = diff(xx);
start = find(d==-1);
stop = find(d==1);
lgt = stop-start;
b = lgt <= C;
d(start(b)) = 0;
d(stop(b)) = 0;
yy = cumsum([1 d]);
yy = reshape(yy, [], m)';
y = yy(:,2:end-1)

Normal Version by Yumnam Kirani Singh

clear;clc;
x=imread('Picture.jpg');
y=rgb2gray(x) ;
z=histeq(y);
t=im2bw(z);
u=double(t);
[a b]=size(u);
for i=1:a
    c=1;
for j=1:b
   if u(i,j)==1
if (j-c)<=5 
    u(i,c:j)=1;
end
c=j;
 end
 end
if (b-c)<=5
   u(i,c:b)=1;
end
end
imshow(u,[]);

Anyone has experience in C++ could implement it with OpenCV, C++ using Mat Structure??

Thank

2014-02-03 05:40:18 -0600 received badge  Editor (source)
2014-02-03 05:28:14 -0600 asked a question Implement imfill matlab in c++ and opencv

Hi I am very new with opencv and c++. I tested some functions with Matlab.

In matlab, I used imfill (BW2 = imfill(BW,'holes')) to the image to fill the holes of the images.

I searched in this forum and I encountered this question Fill holes of a binary image; the accepted answer by HD_Mouse. His Answer :

cv::threshold(image, image_thresh, 125, 255, cv::THRESH_BINARY);
// Loop through the border pixels and if they're black, floodFill from there
cv::Mat mask;
image_thresh.copyTo(mask);
for (int i = 0; i < mask.cols; i++) {
    if (mask.at<char>(0, i) == 0) {
        cv::floodFill(mask, cv::Point(i, 0), 255, 0, 10, 10);
    }   
    if (mask.at<char>(mask.rows-1, i) == 0) {
        cv::floodFill(mask, cv::Point(i, mask.rows-1), 255, 0, 10, 10);
    }
}
for (int i = 0; i < mask.rows; i++) {
    if (mask.at<char>(i, 0) == 0) {
        cv::floodFill(mask, cv::Point(0, i), 255, 0, 10, 10);
    }
    if (mask.at<char>(i, mask.cols-1) == 0) {
        cv::floodFill(mask, cv::Point(mask.cols-1, i), 255, 0, 10, 10);
    }
}


// Compare mask with original.
cv::Mat newImage;
image.copyTo(newImage);
for (int row = 0; row < mask.rows; ++row) {
    for (int col = 0; col < mask.cols; ++col) {
        if (mask.at<char>(row, col) == 0) {
            newImage.at<char>(row, col) = 255;
        }           
    }
}

Instead of using this binarisation

cv::threshold(image, image_thresh, 125, 255, cv::THRESH_BINARY);

I use otsu binarisation from this source

http://kristou.com/2009/08/25/opencv-otsu-thresholding/

I applied this to my image but only some holes are fill while others holes are not filled. I think it might be because of the binarisation. Any idea?? Thank