Ask Your Question

kevgeo's profile - activity

2020-12-08 13:21:53 -0600 received badge  Notable Question (source)
2020-10-28 04:31:15 -0600 received badge  Nice Question (source)
2020-06-11 03:06:51 -0600 received badge  Popular Question (source)
2020-03-10 09:37:59 -0600 received badge  Notable Question (source)
2019-05-29 13:37:58 -0600 received badge  Popular Question (source)
2019-03-02 05:34:56 -0600 received badge  Famous Question (source)
2018-02-05 04:40:17 -0600 received badge  Notable Question (source)
2017-10-28 10:35:53 -0600 received badge  Popular Question (source)
2017-04-13 07:24:42 -0600 marked best answer Creating custom kernels

I want to create custom filters using filter2d function but most of the examples I see use custom methods like ones,zeros and eye but I want to create a 3x3 matrix which contains the values I want.

Like for e.g, [ 1 4 6 -1 3 5 -1 -2 2 ]

How do I make such a kernel using filter2d function?

2016-12-28 12:29:26 -0600 asked a question Can't build opencv 2.4.11 with python

When I try to build opencv 2.4.11 with both c++ and python, an error comes up for python-

Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named numpy.distutils

The thing is numpy is installed for python 2.7.6 and not for python 2.7.9 which is what opencv is trying to build from.

How do I rectify this issue? How can I make opencv build particularly with python 2.7.6 or install numpy with python 2.7.9?

2016-12-12 21:38:07 -0600 commented question Opencv 3 Dnn caffe_googlenet

Hey leofs, has your error been solved? Look at usr/local/include/opencv2 path and see whether your dnn folder is there.

2016-12-12 00:50:51 -0600 asked a question Floating point exception- Running sample program dnn module

I am using Opencv 3.1.0 on ubuntu 14.04. I have successfully built Opencv and wanted to try reading a caffe model and classifying.

I used the program and models from this tutorial

I am able to compile the program but running it gives me the error below-

Attempting to upgrade input file specified using deprecated V1LayerParameter: bvlc_googlenet.caffemodel                                                                                            Successfully upgraded file specified using deprecated V1LayerParameter 
Floating point exception (core dumped)

The floating point exception is coming from line 109 in net.forward() method. I am not able to understand why this problem is coming up?

2016-12-11 23:40:05 -0600 commented question Can't run sample dnn program

Sorry guys, it was a silly mistake. There was a space in the beginning of the caffemodel file name, so it couldn't read it. Later I got another error about failing to parse NetParameter file, so I had to download the caffemodel again and it got solved.

Now I have another error, so I will spend some time to see if there is a similar error online, or else I will put it as a separate issue.

2016-12-10 02:04:43 -0600 commented question Can't run sample dnn program

Hi break, I actually put all the models and image in the same folder with the program and still the error comes.

2016-12-09 23:45:17 -0600 asked a question Can't run sample dnn program

I am using Opencv 3.1.0 on ubuntu 14.04. I have successfully built Opencv and wanted to try reading a caffe model and classifying.

I used the program and models from this tutorial

I am able to compile the program but running it gives me the error below-

OpenCV Error: Unspecified error (FAILED: fs.is_open(). Can't open "bvlc_googlenet.prototxt") iReadProtoFromTextFile, file /home/kevmepls/opt/opencv_contrib/modules/dnn/src/caffe/caffe_io.cpp, line 1077
Can't load network by using the following files: 
prototxt:   bvlc_googlenet.prototxt
caffemodel: bvlc_googlenet.caffemodel
bvlc_googlenet.caffemodel can be downloaded here:
http://dl.caffe.berkeleyvision.org/bvlc_googlenet.caffemodel

I don't understand why it can't read the models?

2016-12-09 22:32:00 -0600 commented answer Trying to run dnn module

Hey pi, using cmake on command line, I got a linking error for protobuf. So I manually copied protobuf from their github repo and it built perfectly fine. I can compile the sample dnn program but can't run it. I guess I will ask it as a separate question.

2016-12-09 22:31:47 -0600 commented answer Trying to run dnn module

Hey pi, using cmake on command line, I got a linking error for protobuf. So I manually copied protobuf from their github repo and it built perfectly fine. I can compile the sample dnn program but can't run it. I guess I will as it as a separate question.

2016-12-09 10:47:17 -0600 commented question Trying to run dnn module

Hey berak, I just copied the protobuf folder from github and it built properly. I am able to compile the sample program but not able to run it. If it doesn't work, I guess I'll just ask it as another question :)

So I'll raise it as an issue on github right as the files should be automatically downloaded instead of manual search.

2016-12-09 04:05:20 -0600 commented question Trying to run dnn module

I am getting cmake warnings which say that the protobuf files are missing which CMakeLists.txt should have downloaded. Will I have to manually move all these files along with the folder to the directory or is there another solution?

2016-12-09 01:25:10 -0600 commented question Trying to run dnn module

Hey berak I'm having such an awesome time here with users like you who help :) . Thanks for the links berak, you might want to edit the second and third links as it is leading to resource not found. For second link in url path, the file name should be boostdesc_bgm_bi.i instead of boostdesc_bgm.bi.i . For third link in url path, the file name should be boostdesc_bgm_hd.i instead of boostdesc_bgm.hd.i .

Now I'm facing this Cmake error sadly :(

CMake Error: Cannot determine link language for target "libprotobuf".
CMake Error: CMake can not determine linker language for target: libprotobuf

Do you know how to resolve this? I need libprotobuf to read caffe files.

2016-12-08 23:09:10 -0600 commented question Trying to run dnn module

Hey berak, I tried following this cmake command from this website

It seems to include the Opencv_contrib module but I'm facing this failure of download of boostdesc_bgm_bi.i file. I tried finding this file online but to no avail and this stackoverflow question faces the same problem but it hasn't been answered since Novemeber 19th.

This is the cmake error output-

CMake Error at /home/kevmepls/opt/opencv/cmake/OpenCVUtils.cmake:1025 (message):

Failed to download boostdesc_bgm_bi.i. Status=1;"Unsupported protocol"

2016-12-08 23:09:01 -0600 commented question Trying to run dnn module

Hey berak, I tried following this cmake command from this website

It seems to include the Opencv_contrib module but I'm facing this failure of download of boostdesc_bgm_bi.i file. I tried finding this file online but to no avail and this stackoverflow question faces the same problem but it hasn't been answered since Novemeber 19th?

This is the cmake error output- CMake Error at /home/kevmepls/opt/opencv/cmake/OpenCVUtils.cmake:1025 (message): Failed to download boostdesc_bgm_bi.i. Status=1;"Unsupported protocol" Call Stack (most recent call first):

2016-12-08 11:31:03 -0600 commented question Trying to run dnn module

Even with absolute path, the cmake output is the same.

2016-12-08 10:56:29 -0600 commented question Trying to run dnn module

Could it be a problem with cmake then? Is there any other reason why it may be failing?

2016-12-08 10:42:02 -0600 commented question Trying to run dnn module

Yes, it is the correct path. Sometimes without the ~, it goes to the other opt folder and not the one i made at home.

2016-12-08 10:41:18 -0600 commented question Trying to run dnn module

what did you do to format the output? Also as you can see from output, the extra modules from opencv_contrib are not being built but are also not unavailable? How is that possible even when my cmake path points to the opencv_contrib folder?

2016-12-08 10:32:31 -0600 commented question Trying to run dnn module

I'm really sorry but I'm not sure how to edit the cmake output properly in opencv q&A

2016-12-08 09:37:03 -0600 commented question Trying to run dnn module

Hi berak,

  1. Yes i ran make install.
  2. When i run the pkg-config --cflags --libs opencv command, there is no mention of dnn module.
  3. I tried running using cmake from the link you gave but it gives the same error.
2016-12-08 06:28:22 -0600 asked a question Trying to run dnn module

I have installed Opencv 3.1.0 along with Opencv_contrib module with the aim of reading caffe models into Opencv. I followed the official Opencv installation documentation and with a change in Cmake command, I was able to build it successfully on Ubuntu 14.04lts.

When I type the following command to run the sample program -

g++ -o 1 ssd_object_detection.cpp  `pkg-config --cflags --libs opencv`

I get the error below.

ssd_object_detection.cpp:1:27: fatal error: opencv2/dnn.hpp: No such file or directory
 #include <opencv2/dnn.hpp>
                           ^
compilation terminated.

I looked at the opencv_contrib github repo and they mentioned that you have to run it with a linker to the specific module which you want. So my command then became-

g++ -o 1 ssd_object_detection.cpp  `pkg-config --cflags --libs opencv` -lopencv_dnn

But I still get the same error. Does this mean that my dnn module hasn't been built properly? The error is from the header file opencv2/dnn.hpp not being recognised but I don't know why?

The sample program is from this link- sample program to load caffe model and run

Output of cmake-

cmake -D CMAKE_BUILD_TYPE=Release -D OPENCV_EXTRA_MODULES=~/opt/opencv_contrib/modules -D CMAKE_INSTALL_PREFIX=/usr/local ..
-- The CXX compiler identification is GNU 4.8.4
-- The C compiler identification is GNU 4.8.4
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Detected version of GNU GCC: 48 (408)
-- Performing Test HAVE_CXX_FSIGNED_CHAR
-- Performing Test HAVE_CXX_FSIGNED_CHAR - Success
-- Performing Test HAVE_C_FSIGNED_CHAR
-- Performing Test HAVE_C_FSIGNED_CHAR - Success
-- Performing Test HAVE_CXX_W
-- Performing Test HAVE_CXX_W - Success
-- Performing Test HAVE_C_W
-- Performing Test HAVE_C_W - Success
-- Performing Test HAVE_CXX_WALL
-- Performing Test HAVE_CXX_WALL - Success
-- Performing Test HAVE_C_WALL
-- Performing Test HAVE_C_WALL - Success
-- Performing Test HAVE_CXX_WERROR_RETURN_TYPE
-- Performing Test HAVE_CXX_WERROR_RETURN_TYPE - Success
-- Performing Test HAVE_C_WERROR_RETURN_TYPE
-- Performing Test HAVE_C_WERROR_RETURN_TYPE - Success
-- Performing Test HAVE_CXX_WERROR_NON_VIRTUAL_DTOR
-- Performing Test HAVE_CXX_WERROR_NON_VIRTUAL_DTOR - Success
-- Performing Test HAVE_C_WERROR_NON_VIRTUAL_DTOR
-- Performing Test HAVE_C_WERROR_NON_VIRTUAL_DTOR - Success
-- Performing Test HAVE_CXX_WERROR_ADDRESS
-- Performing Test HAVE_CXX_WERROR_ADDRESS - Success
-- Performing Test HAVE_C_WERROR_ADDRESS
-- Performing Test HAVE_C_WERROR_ADDRESS - Success
-- Performing Test HAVE_CXX_WERROR_SEQUENCE_POINT
-- Performing Test HAVE_CXX_WERROR_SEQUENCE_POINT - Success
-- Performing Test HAVE_C_WERROR_SEQUENCE_POINT
-- Performing Test HAVE_C_WERROR_SEQUENCE_POINT - Success
-- Performing Test HAVE_CXX_WFORMAT
-- Performing Test HAVE_CXX_WFORMAT - Success
-- Performing Test HAVE_C_WFORMAT
-- Performing Test HAVE_C_WFORMAT - Success
-- Performing Test HAVE_CXX_WERROR_FORMAT_SECURITY
-- Performing Test HAVE_CXX_WERROR_FORMAT_SECURITY - Success
-- Performing Test HAVE_C_WERROR_FORMAT_SECURITY
-- Performing Test HAVE_C_WERROR_FORMAT_SECURITY - Success
-- Performing Test HAVE_CXX_WMISSING_DECLARATIONS
-- Performing Test HAVE_CXX_WMISSING_DECLARATIONS - Success
-- Performing Test HAVE_C_WMISSING_DECLARATIONS
-- Performing Test HAVE_C_WMISSING_DECLARATIONS - Success
-- Performing Test HAVE_CXX_WMISSING_PROTOTYPES
-- Performing Test HAVE_CXX_WMISSING_PROTOTYPES - Failed
-- Performing Test HAVE_C_WMISSING_PROTOTYPES
-- Performing Test HAVE_C_WMISSING_PROTOTYPES - Success
-- Performing Test HAVE_CXX_WSTRICT_PROTOTYPES
-- Performing Test HAVE_CXX_WSTRICT_PROTOTYPES - Failed
-- Performing Test HAVE_C_WSTRICT_PROTOTYPES
-- Performing Test HAVE_C_WSTRICT_PROTOTYPES - Success
-- Performing Test HAVE_CXX_WUNDEF
-- Performing Test HAVE_CXX_WUNDEF - Success
-- Performing Test HAVE_C_WUNDEF
-- Performing Test HAVE_C_WUNDEF - Success
-- Performing Test HAVE_CXX_WINIT_SELF
-- Performing Test HAVE_CXX_WINIT_SELF - Success
-- Performing Test HAVE_C_WINIT_SELF
-- Performing Test HAVE_C_WINIT_SELF - Success
-- Performing Test HAVE_CXX_WPOINTER_ARITH
-- Performing Test ...
(more)
2016-11-07 23:33:36 -0600 commented question Sobel edge detection Implementation

I do padding to take care of edge pixels.

If I use gradient_y.at<char>(r - radius, c - radius) = s; then my edges become much worse. I don't understand the reason why but when I'm dividing by 30, the edges becomes much more clearer.

In the link below, final1.png is s/30, final2.png is s.

link

2016-11-06 23:39:05 -0600 commented question Sobel edge detection Implementation

Hey LBerger, actually that indexing is required to access all the pixels in the image. Initially, I pad the image with one pixel across the whole border so that I could implement correlaton properly.

I'm calculating gradient magnitude which is sum of square of gradients in x and y direction, so the negative values are getting squared. Or am I suppose to ignore the negative gradients?

Oh so sobel doens't require a threshold? Do you have any idea how the OpenCV implementation works as I'm almost following allthe steps in Sobel edge detection but still my output is different from Opencv?

2016-11-05 13:33:54 -0600 asked a question Sobel edge detection Implementation

I am trying to implement sobel edge detection from scratch but my output can't seem to match with OpenCV's sobel function. I performed correlation on the image with the sobel operator in both x and y directions and then computed gradient magnitude as square root of sum of squares of magnitudes in both x & y direction. I believe the problem is how I assign the threshold for edge detection.

Images-

1.Original Image-

image description

2.My implementation of Sobel Edge Detection - image description

3.Opencv Sobel edge function output - image description

Code-

#include <iostream>
#include <bits/stdc++.h>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/opencv.hpp"
#include "opencv2/imgproc/imgproc.hpp" 
#include <opencv2/objdetect/objdetect.hpp>
#include <math.h>

using namespace cv; 
using namespace std; 

int main()
{
// Reading image
Mat img = imread("1.jpg");


// Blurring and Converting to grayscale
Mat img_gray,image_blur;
GaussianBlur( img, image_blur, Size(5,5), 3, 3);
    cvtColor(image_blur,img_gray,CV_RGB2GRAY);

int cols = img_gray.cols;
int rows = img_gray.rows;

// Creating sobel operator in x direction
int sobel_x[3][3] = {-1,0,1,-2,0,2,-1,0,1};
// Creating sobel operator in y direction
int sobel_y[3][3] = {-1,-2,-1,0,0,0,1,2,1};


int radius = 1;

// Handle border issues
Mat _src;
copyMakeBorder(img_gray, _src, radius, radius, radius, radius, BORDER_REFLECT101);

// Create output matrix
Mat gradient_x = img_gray.clone();
Mat gradient_y = img_gray.clone();
Mat gradient_f = img_gray.clone();

int max=0;

// Correlation loop in x direction 

// Iterate on image 
for (int r = radius; r < _src.rows - radius; ++r)
{
    for (int c = radius; c < _src.cols - radius; ++c)
    {
        int s = 0;

        // Iterate on kernel
        for (int i = -radius; i <= radius; ++i)
        {
            for (int j = -radius; j <= radius; ++j)
            {
                s += _src.at<uchar>(r + i, c + j) * sobel_x[i + radius][j + radius];
            }
        }
        gradient_x.at<uchar>(r - radius, c - radius) = s/30;

        /*if(s>200)
            gradient.at<uchar>(r - radius, c - radius) = 255;
        else
            gradient.at<uchar>(r - radius, c - radius) = 0;
        */    
    }
}


// Conrrelation loop in y direction 

// Iterate on image 
for (int r = radius; r < _src.rows - radius; ++r)
{
    for (int c = radius; c < _src.cols - radius; ++c)
    {
        int s = 0;

        // Iterate on kernel
        for (int i = -radius; i <= radius; ++i)
        {
            for (int j = -radius; j <= radius; ++j)
            {
                s += _src.at<uchar>(r + i, c + j) * sobel_y[i + radius][j + radius];
            }
        }

        gradient_y.at<uchar>(r - radius, c - radius) = s/30;

        /*if(s>200)
            gradient.at<uchar>(r - radius, c - radius) = 255;
        else
            gradient.at<uchar>(r - radius, c - radius) = 0;
        */    
    }
}




//Calculating gradient magnitude
for(int i=0; i<gradient_f.rows; i++)
{
    for(int j=0; j<gradient_f.cols; j++)
    {
        gradient_f.at<uchar>(i,j) = sqrt( pow(gradient_x.at<uchar>(i,j),2) + pow(gradient_y.at<uchar>(i,j),2) );  

         if(gradient_f.at<uchar>(i,j) >240)
            gradient_f.at<uchar>(i,j) = 100;
        else
            gradient_f.at<uchar>(i,j) = 0;
    }
}




imshow("grad magnitude",gradient_f);
waitKey(0);




cv::Mat Gx, Gy; int ksize=3;
Mat abs_grad_x, abs_grad_y;
cv::Sobel(img_gray, Gx, CV_8U, 1, 0, ksize);
convertScaleAbs( Gx, abs_grad_x );
cv ...
(more)
2016-11-03 19:49:17 -0600 commented answer Canny Edge Detection- Non Maximum Surpression Implementation

Yes, it actually gave me much thinner edges. Do you have any idea why my sobel gradients isn't coming out properly? I changed the value of my sobel operator in y direction to int sobel_y[3][3] = {-1,-2,-1,0,0,0,1,2,1}; . I thought that was the mistake but barely any change is there.

2016-11-01 04:31:21 -0600 asked a question Canny Edge Detection- Non Maximum Surpression Implementation

I am trying to implement the Canny edge detection algorithm from scratch with the help of OpenCV. I am facing a problem implementing the Non-Maximum Suppression step which helps to thin the edges.

My logic is to first compute the intensity gradient vector, then group it in either 0,45,90,135 degrees direction and then try to find local maxima. The method to find this local maxima is by making sure that current pixel is greater than succeeding and preceeding pixel in same direction. If not, I assign value of zero to this pixel. Using this logic, I'm still not able to thin the edges. I feel the error is when I'm computing the intensity gradient vector for each pixel.

Here is my code-

#include <iostream>
#include <bits/stdc++.h>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/opencv.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <opencv2/objdetect/objdetect.hpp>
#include <math.h>
using namespace cv;  
using namespace std; 

int main()
{
// Reading image
Mat img = imread("1.jpg");

// Displaying image
//imshow("Original Image",img);
//waitKey(0);

// Converting to grayscale
Mat img_gray,image_gray;
cvtColor(img,image_gray,CV_RGB2GRAY);
GaussianBlur( image_gray, img_gray, Size(15,15), 3, 3);


// Displaying grayscale image
imshow("Original Image",img_gray);
waitKey(0);


int cols = img_gray.cols;
int rows = img_gray.rows;

// Creating sobel operator in x direction
int sobel_x[3][3] = {-1,0,1,-2,0,2,-1,0,1};
// Creating sobel operator in y direction
int sobel_y[3][3] = {1,2,1,0,0,0,-1,-2,-1};


int radius = 1;

// Handle border issues
Mat _src;
copyMakeBorder(img_gray, _src, radius, radius, radius, radius, BORDER_REFLECT101);

// Create output matrix
Mat gradient_x = img_gray.clone();
Mat gradient_y = img_gray.clone();
Mat gradient_f = img_gray.clone();
Mat gradient_mag = img_gray.clone();

// Conrrelation loop in x direction 

// Iterate on image 
for (int r = radius; r < _src.rows - radius; ++r)
{
    for (int c = radius; c < _src.cols - radius; ++c)
    {
        int s = 0;

        // Iterate on kernel
        for (int i = -radius; i <= radius; ++i)
        {
            for (int j = -radius; j <= radius; ++j)
            {
                s += _src.at<uchar>(r + i, c + j) * sobel_x[i + radius][j + radius];
            }
        }
        gradient_x.at<uchar>(r - radius, c - radius) = s/8;

        /*if(s>200)
            gradient.at<uchar>(r - radius, c - radius) = 255;
        else
            gradient.at<uchar>(r - radius, c - radius) = 0;
        */    
    }
}

// Conrrelation loop in y direction 

// Iterate on image 
for (int r = radius; r < _src.rows - radius; ++r)
{
    for (int c = radius; c < _src.cols - radius; ++c)
    {
        int s = 0;

        // Iterate on kernel
        for (int i = -radius; i <= radius; ++i)
        {
            for (int j = -radius; j <= radius; ++j)
            {
                s += _src.at<uchar>(r + i, c + j) * sobel_y[i + radius][j + radius];
            }
        }
        gradient_y.at<uchar>(r - radius, c - radius) = s/8;

        /*if(s>200)
            gradient.at<uchar>(r - radius, c - radius) = 255;
        else
            gradient.at<uchar>(r - radius, c - radius) = 0;
        */    
    }
}

///cout<<endl<<"max:"<<max;
//cout<<img_gray.rows;
//cout<<endl<<_src.rows;
cout<<endl<<gradient_x.rows;
cout<<endl<<gradient_y.rows;
cout<<endl<<gradient_f.rows<<gradient_f.cols;   


//Calculating gradient magnitude
for(int i=0; i ...
(more)
2016-10-18 11:06:39 -0600 commented question Correlation Implementation

Sorry for the late reply, @LBerger I didn't understand exactly how template matching can be used for correlation implementation.

2016-10-13 03:55:58 -0600 asked a question Correlation Implementation

I want to basically write code from scratch to do correlation on a given image with a kernel(without using filter2d function).

I am trying to find a general way of correlating image with kernel( mxm size where m an is odd number) but I can't seem to think of a good algorithm that will work for kernel of all sizes. In case of a boundary issue, we compute correlation for each pixel of image as long as the center of the kernel is on this pixel.

My idea is to first classify the pixels into two types, first one being pixels where simple multiplication with kernel is fine. The problem comes with the second type that is the boundary pixels, the pixels at the edges of the image. I can't seem to find a general way and I seem to end up hard-coding it to compute correlation for these pixels for different sizes of kernel.

Does anyone have any ideas or suggestions for a simpler implementation?

2016-07-26 21:51:58 -0600 asked a question findChessboardCorners returing false boolean value?

I am using findChessboardCorners function to find the corners in a chessboard image. image description

When I am executing the function on this image, I am getting an array of detected corners but the bool value returned by the function is zero. Shouldn't it be one since I'm getting an array of detected corners?

Code-

Mat inImage;
inImage = imread("left01.jpg");
//-> Output
vector<Point2f> corners; // This will be filled by the detected corners

bool found = findChessboardCorners( inImage, Size(8,6), corners, CV_CALIB_CB_ADAPTIVE_THRESH );

cout<<"found::"<<found<<endl;
cout<<"number of corners detected:"<<corners.size()<<endl;
2016-07-23 03:11:25 -0600 commented answer why composeRT function is showing error for column vectors?

Thanks a lot berak for the swift answers