Ask Your Question

Gilad Darmon's profile - activity

2019-11-02 17:24:36 -0600 answered a question How to install opencv 4.1 using CMake and Visual Studio 2013?

The answer for this is simple but takes a lot of effort to understand it for me. Visual Studio 2013 doesn't support all

2019-10-19 04:36:29 -0600 received badge  Necromancer (source)
2019-10-18 15:12:08 -0600 answered a question How to install opencv 4.1 using CMake and Visual Studio 2013?

I was able to compile most of the parts of OpenCV C++ with Visual Studio 2013, you must have update 5 installed as well.

2019-10-18 01:49:34 -0600 edited question OpenCV4.1.2 build with visual studio 2013 is it possible?

OpenCV4.1.2 build with visual studio 2013 is it possible? am trying to compile opencv 4.1.2 c++ for visual studio 2013 x

2019-10-18 01:48:52 -0600 asked a question OpenCV4.1.2 build with visual studio 2013 is it possible?

OpenCV4.1.2 build with visual studio 2013 is it possible? am trying to compile opencv 4.1.2 c++ for visual studio 2013 x

2019-10-17 17:48:32 -0600 answered a question How to install opencv 4.1 using CMake and Visual Studio 2013?

Can some answer this? really is this not compatible for VS2013?

2018-06-19 03:51:53 -0600 received badge  Famous Question (source)
2017-02-02 07:28:37 -0600 received badge  Notable Question (source)
2016-08-27 04:36:17 -0600 received badge  Popular Question (source)
2015-04-26 11:55:13 -0600 asked a question How Can I build openCV for /MD flag

Hello,
I want to build openCV for /MD and not /MT because I want to use openCV with C++/CLI
and /CLR is not compatible with /MT.
I would like to use openCV for static linking with C++/CLI.

I have followed this tutorial. http://docs.opencv.org/doc/tutorials/...

but I do not understand how to compile it to /MD.

I'd like your help please

2015-04-10 16:56:58 -0600 asked a question bayer Image matrix concatenation 2D to 3D

hello all I was trying to convert this matlab code into c++

 imageData = toolbox.bayer.ColorOrder.cat( imageData, 0, 3);

this is imageData before

1   2   3   4   5   6   7   8   9   10
11  12  13  14  15  16  17  18  19  20
21  22  23  24  25  26  27  28  29  30
31  32  33  34  35  36  37  38  39  40

this is image data after:

val(:,:,1) =

 1     3     5     7     9
21    23    25    27    29
val(:,:,2) =

 2     4     6     8    10
22    24    26    28    30
val(:,:,3) =

11    13    15    17    19
31    33    35    37    39
val(:,:,4) =

12    14    16    18    20
32    34    36    38    40

I couldn't find a way to this with openCV cv::Mat, is there a way to separate Bayer image into it's channels in openCV? i'm not talking about demosaicing. just getting the RGGB channels as R,G,G,B matrices

can you suggest a way ?

except copying the elements one by one ?

2015-04-06 09:04:45 -0600 asked a question 2D matrix reshape into 3D matrix

I Can see that opencv Reshape has been overloaded with

Mat reshape(int cn, int rows=0) const;
Mat reshape(int cn, int newndims, const int* newsz) const;

I wan to create this matlab code

original matrix gili = 2x24

1   2   3   4   5   6   7   8   9   10  11  12  13  14  15  16  17  18  19  20  21  22  23  24
25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48

reshapeGili = 4x6x2

reshape([gili(1,:) gili(2,:)], 4, 6, 2);


val(:,:,1) =

     1     5     9    13    17    21
     2     6    10    14    18    22
     3     7    11    15    19    23
     4     8    12    16    20    24


val(:,:,2) =

    25    29    33    37    41    45
    26    30    34    38    42    46
    27    31    35    39    43    47
    28    32    36    40    44    48

Can this be done using reshape?

I can create int newdims[] = { 4, 6, 2 };

but what does const int*newsz mean?

if I can't use reshape I will just create a new matrix and copy the values to it.

   int sizes[] = { 4, 6, 2 };
    cv::Mat xyFinal(3, sizes, CV_64F, cv::Scalar(0));
    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 6; j++)
        {
            xyFinal.at<double>(i,j,0) = xyFinalMat.at<double>(0,i*6+j);
            xyFinal.at<double>(i,j,1) = xyFinalMat.at<double>(1,i*6+j);
        }
    }

the code works however when I try to print the output matrix

ofstream myfile;
    myfile.open("C:\\Users\\gdarmon\\Desktop\\OpenCV_CR.txt");
    myfile << xyFinal;
    myfile.close();


OpenCV Error: Assertion failed (m.dims <= 2) in cv::writeMat, file C:\buildslave
64\win64_amdocl\2_4_PackSlave-win64-vc11-shared\opencv\modules\core\src\out.cpp,
 line 117
2015-04-04 06:22:58 -0600 commented question 2D matrix multiplication in 2D matrix error

OK I have updated the solution to my problem thanks all

2015-04-03 13:08:35 -0600 received badge  Student (source)
2015-04-03 06:53:34 -0600 commented question 2D matrix multiplication in 2D matrix error

@boaz001 Thanks for the comment. I have added the exception

2015-04-03 04:52:27 -0600 asked a question 2D matrix multiplication in 2D matrix error

UPDATE I have a found a solution to my problem I need to work with CV_64F / double and everything is working fine.

My input are two double vectors I want to create b = (X'*X)^-1*X'*y = inv(X'*X)*X'*y*

the original matlab code is :

function c = linear_mapping(x0, y0)
    % Reshape input values just to make sure they are column order
    x0 = x0(:); % column wise order
    y0 = y0(:); % column wise order

    % Linear mapping y = X*b, where X = [1, x] and b are coefficients
    % Solving b = (X'*X)^-1*X'*y = inv(X'*X)*X'*y
    X = [ones(size(x0)), x0];
    b = linsolve(X, y0);
    c(1) = b(2);
    c(2) = b(1);
end

i'll update my code which is now creating the matrices i want the multiplication is different from matlab's result matlab's version :

X =

1.0e+03 *

0.0010    1.0743
0.0010    1.0740

X'

ans =

1.0e+03 *

0.0010    0.0010
1.0743    1.0740

X'*X

ans =

1.0e+06 *

0.0000    0.0021
0.0021    2.3075

inv(X'*X)

25402233.6743484    -23649.3170474466
-23649.3170474466   22.0173633149477

my new openCV version

CentroidXY Utilities::LinearMapping(std::vector<double> x0, std::vector<double> y0)
{       
    cv::Mat X = cv::Mat::ones(x0.size(),2, CV_32F);
    for (int i = 0; i < x0.size(); i++)
    {
        X.at<float>(i,1) = x0[i];
    }       
    cv::Mat XTrans;

    cv::transpose(X,XTrans);
    cv::Mat invMat;
    /*% Solving b = (X'*X)^-1*X'*y = inv(X'*X)*X'*y*/

    cv::Mat b = XTrans *X; 
    invMat  =b.inv();   
}

here is my output:

 X: 
[1, 1074.272;
  1, 1073.9705]

 X': 
[1, 1;
  1074.272, 1073.9705]

 X'*X 
[2, 2148.2424;
  2148.2424, 2307472.8]

 inv(X'*X)
[-51162084, 47631.574;
  47631.574, -44.344692]

once again what is the difference?

2015-04-01 15:38:23 -0600 asked a question interp1 in c++/opencv for vector<double>

here is the matlab code i'm trying to transform into c++

if numel(f) < 31
   f = interp1(f, linspace(1, numel(f), 31), 'linear');
          objCenter = 16;
end

here is

vector<double> Utilities::linspace(double a, double b, int n) {
    vector<double> array;
    double step = (b-a) / (n-1);

    while(a <= b)
    {
        array.push_back(a);
        a += step;           
    }
    return array;
}

Is there no openCV function which does a linear interpolation? I have found this https://github.com/bytefish/colormaps...

but I can't believe there is no interp1... Am i wrong?

Update I'm trying to use cv::resize()

if (distanceF.size() < 31)
        {
            cv::Mat input(distanceF);
            cv::Mat output(1,31,CV_32F);

            cv::resize(input,output,output.size(),0,0,cv::INTER_LINEAR);
            distanceF.clear();
            for (int i = 0; i < 31; i++)
            {
                distanceF.push_back(output.at<float>(i));
            }
            objCenter =16;
        }
2015-04-01 10:13:52 -0600 commented question cvCreateImage return 205 values and not 0

@StevenPuttemans i need to creaye bwlabel function. In my case i need to label squares or rectangles.

2015-04-01 08:23:27 -0600 commented question cvCreateImage return 205 values and not 0

@StevenPuttemans and @FooBar i need to do labeling. Opencv 2.4.10 doesn't support stuff like matlab's bwlabel. This is why I'm using cvblobs

2015-04-01 08:05:50 -0600 commented question cvCreateImage return 205 values and not 0

findContours finds the shapes. but I can't see how do I do stuff like coloring the whole contour. anyway i will have a second look

2015-04-01 07:47:13 -0600 commented question cvCreateImage return 205 values and not 0

@FooBar it is only because i'm using cvBlobsLib which uses it

2015-04-01 07:08:15 -0600 asked a question cvCreateImage return 205 values and not 0

This my filtered matrix after the following code:

IplImage* img_bw_1 = new IplImage(bwImg);
IplImage* filtered = cvCreateImage( cvGetSize( img_bw_1 ),
    IPL_DEPTH_8U,
    3 ); 

 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205,

before that code bwImag matrix was

0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,

what am I doing wrong here?

// EDIT: Crosspost at Stackoverflow: http://stackoverflow.com/questions/29...

2015-03-30 16:01:07 -0600 asked a question matlab find() function fast min and max elements in opencv

the matlab code I want to covert is:

[maY, maX] = find(imTemp);
sx = [min(maX(:)) max(maX(:))].*scaleRatio;
sy = [min(maY(:)) max(maY(:))].*scaleRatio;

I have used openCV's findNonZero() like so:

  cv::Mat nonZeroCoordinates;
        cv::findNonZero(imTemp, nonZeroCoordinates);
        double maxX = nonZeroCoordinates.at<cv::Point>(0).x;
        double minX = nonZeroCoordinates.at<cv::Point>(0).x;
        double maxY = nonZeroCoordinates.at<cv::Point>(0).y;
        double minY = nonZeroCoordinates.at<cv::Point>(0).y;
        for (int i = 0; i < nonZeroCoordinates.total(); i++ ) 
        {
            if (nonZeroCoordinates.at<cv::Point>(i).x > maxX)
            {
                maxX = nonZeroCoordinates.at<cv::Point>(i).x;
            }
            if(nonZeroCoordinates.at<cv::Point>(i).x < minX)
            {
                minX = nonZeroCoordinates.at<cv::Point>(i).x;
            }
            if (nonZeroCoordinates.at<cv::Point>(i).y > maxY)
            {
                maxY = nonZeroCoordinates.at<cv::Point>(i).y;
            }
            if(nonZeroCoordinates.at<cv::Point>(i).y < minY)
            {
                minY = nonZeroCoordinates.at<cv::Point>(i).y;
            }
        }

is there a faster way to find minx, maxX, minY, maxY??

2015-03-29 16:21:47 -0600 received badge  Scholar (source)
2015-03-29 07:44:13 -0600 asked a question implementing matlab hist() in c++

here is the line of code I want to implement

kb = [];
    for k = 1:length(nRef)
        for n=1:length(dCmpInd{k})
            x = [centroid(nRef{k}, 1), centroid(dCmpInd{k}(n),1)];
            y = [centroid(nRef{k}, 2), centroid(dCmpInd{k}(n),2)];

            [x,ind] = sort(x);
            y = y(ind);
            kb = [kb diff(y) / diff(x)];
        end
    end

    theta = (atan(kb));

    [N, X] = hist(abs(theta),2);

here is my c++ code:

 std::vector<double> kb;
    std::vector<double> theta;
    for (int k = 0; k < nRef.size(); k++)
    {
        for (int n = 0; n < dCmpInd[k].size(); n++)
        {
            double x1 = centroids[nRef[k]].m_X; double x2 = centroids[dCmpInd[k][n]].m_X;
            double y1 = centroids[nRef[k]].m_Y; double y2 = centroids[dCmpInd[k][n]].m_Y;
            if (x1 <x2)
            {
                double tempdiff = (y2-y1)/(x2-x1);              
                kb.push_back(tempdiff);
                theta.push_back(abs(atan(tempdiff)));
            }
            else
            {
                double tempdiff = (y1-y2)/(x1-x2);
                kb.push_back(tempdiff);
                theta.push_back(abs(atan(tempdiff)));
            }
        }
    }

is there a quick way to implement :

[N,X] = hist(theta,2);

I can use openCV 2.4.10 as well but calcHist() isn't really the same, I need to create 2 bins.

my input is 1D array:

0.00598881028540019 1.56120677124307    0.00598881028540019 0.00669537049433832 1.37723800334516    1.37723800334516    1.36424594043624    1.56120677124307    0.0152220988707370

the output is:

X= 0.394793300524817    1.17240228100365
 N = 4 5
2015-03-29 07:43:48 -0600 received badge  Enthusiast
2015-03-27 16:29:47 -0600 commented answer regionprops vs. findContours

Cool, looks like a great solution for my problem. I will try it with the rest of my algorithm. Thanks, Is there a way no to create all of the rectangles? just the best fitted ones to the square? i mean the green ones you added?

2015-03-27 03:00:44 -0600 commented question regionprops vs. findContours

Yes correct i want to extract the squares, uploaded the original image

2015-03-26 21:08:22 -0600 commented question regionprops vs. findContours

Can it be that because i'm doing dst.convertTo(dst,CV_8U); i'm loosing some information ? what do i need to do ?

2015-03-26 21:00:57 -0600 edited question regionprops vs. findContours

Is there a way to get the same results for cDist=regionprops(bwImg, 'Area'); and openCV's findContours?

Here is what I have tried so far:

dst.convertTo(dst,CV_8U);
cv::vector<cv::vector<cv::Point> > contours_1;
cv::vector<cv::Vec4i> hierarchy_1;
cv::findContours(dst,contours_1,hierarchy_1,CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE);

double maxLabelSize = (dst.rows/4.0) * (dst.cols/6.0);
double minLabelSize = ((dst.rows/40.0) * (dst.cols/60.0));

cv::vector<cv::vector<cv::Point> > goodContours;
for (int i = 0; i < contours_1.size(); i++)
{
    double size = cv::contourArea(contours_1[i]);
    if (size < maxLabelSize && size > minLabelSize)
    {
        goodContours.push_back(contours_1[i]);
    }
}

cv::Mat filterContours = cv::Mat::zeros(dst.size(),CV_8UC3);    
for (int i = 0; i < goodContours.size(); i++)
{
    cv::RNG rng(12345);
    cv::Scalar color = cv::Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
    drawContours( filterContours, goodContours, i, color, 2, 8, hierarchy_1, 0, cv::Point() );
}

cv::imshow( "Contours", filterContours );
cv::waitKey(0);

the source image was created using average smoothing and

cv::Mat utils::im2bw(cv::Mat src, double grayThresh)
{
    cv::Mat dst;
    cv::threshold(src, dst, grayThresh, 1, CV_THRESH_BINARY);
    return dst; 
}

original image image description

OpenCV's result

Matlab's Version:

% Calculate each separated object area
    cDist=regionprops(bwImg, 'Area');
    cDist=[cDist.Area];

    % Label each object
    [bwImgLabeled, ~]=bwlabel(bwImg);

    % Calculate min and max object size based on assumptions
    maxLabelSize = prod(size(imageData)./[4 6]);
    minLabelSize = prod(size(imageData)./[4 6]./10);

    % Find label indices for objects that are too large or too small
    remInd = find(cDist > maxLabelSize);
    remInd = [remInd find(cDist < minLabelSize)];

    % Remove over/undersized objects
    for n=1:length(remInd)
        ri = bwImgLabeled == remInd(n);
        bwImgLabeled(ri) = 0;
    end

image description

Matlab's result

Please note the left bottom square is missing from the openCV image. should I do Canny edge detection before findContours?

2015-03-26 20:58:36 -0600 commented question regionprops vs. findContours

I have uploaded the source images, which are both black and white images, and the function which creates the black and white image. I did some some smoothing filtering, but as you can see the images are identical.