Ask Your Question

Roy2511's profile - activity

2016-11-02 03:16:56 -0600 answered a question Canny Edge Detection- Non Maximum Surpression Implementation

Maybe the issue is with how you're calculating the Sobel gradients. Try this .

cv::Mat Gx, Gy;
cv::Sobel(img, Gx, CV_64F, 1, 0, ksize);
cv::Sobel(img, Gy, CV_64F, 0, 1, ksize);

where ksize is the size of the Sobel kernel. (in your case, ksize = 3)

2016-10-27 00:54:49 -0600 commented answer How to classify an object that does not belong to the trained classess using MLP

I wouldn't classify it as an overfitting, but yes, the consequences are similar.

The only thing I can think of right now is apply your feature extraction algorithm and then instead of passing it through an ANN right away, pass it through a thresholding algorithm. Use the existing classes to form sort of a D-dimensional sphere around a center point (which can be the feature average of the known classes). If the data point falls outside this circle then store it as 'unknown'. Once you have enough in the unknown pool, you can retrain the NN with x+1 classes and update the thresholding algorithm with the new data.

2016-10-26 01:28:51 -0600 answered a question How to classify an object that does not belong to the trained classess using MLP

ANNs don't work like that. If a certain item is not in your training set, and you pass that item as an input to your network then it will classify that item to the closest possible set (ideally).

One possible solution is using a regression model, that way you can possibly use the classification error to penalise this misclassification. But this method is pretty dangerous, and not recommended.

2016-10-26 01:11:52 -0600 asked a question Python and C++ are giving different results for Hough Circle detection

Hi all,

So I have implemented the same code in both C++ and Python. The code does nothing much, just reads a grayscale image, implements the hough circle detection algorithm and gives the output.

Code in C++:

#include <iostream>
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/opencv.hpp"

#define IMAGE_ROW 1882

int t_rows, t_cols;
using namespace cv;

int main()
{
    Mat img = imread("<path>\\org5_6.bmp", 0);
    int circle[3];

    std::cout << "OpenCV Version = " << CV_VERSION << '\n';
    if (!img.data)
    {
        std::cout << "Could not load image." << '\n';
    }
    else
    {
        std::cout << "Start HCircles.. " << '\n';

        t_rows = img.rows;
        t_cols = img.cols;

        std::cout << "t_cols : " << img.cols << std::endl;
        std::cout << "t_rows : " << img.rows << std::endl;

        std::vector<cv::Vec3f> circles;
        int circlesExist = 1;
        Mat GrayImg = img;
        Mat ResizedImg;
        Mat BlurredImg;
        int black_circle_radius_low;
        int black_circle_radius_upper;

        //cvtColor(RGBimg, GrayImg, CV_BGR2GRAY);
        //GrayImg = imread("/Volumes/Seagate Backup Plus Drive/CppTest/org5_6.bmp", 0);
        Size size(t_cols * IMAGE_ROW / t_rows, IMAGE_ROW);
        resize(GrayImg, ResizedImg, size);

        std::cout << "After resizing" << '\n';
        std::cout << "t_cols : " << ResizedImg.cols << std::endl;
        std::cout << "t_rows : " << ResizedImg.rows << std::endl;
        t_rows = ResizedImg.rows;
        t_cols = ResizedImg.cols;

        medianBlur(ResizedImg, BlurredImg, 5);
        Mat BlurredImgCopy = BlurredImg;
        black_circle_radius_low = (int)(0.4 * std::min(t_rows, t_cols));
        black_circle_radius_upper = (int)(0.45 * std::min(t_rows, t_cols));

        std::cout << "Radius min = " << black_circle_radius_low << '\n';
        std::cout << "Radius max = " << black_circle_radius_upper << '\n';

        HoughCircles(BlurredImg, circles, CV_HOUGH_GRADIENT, 1, 300, 30, 30, black_circle_radius_low, black_circle_radius_upper);

        std::cout << "Total number of circles detected = " << circles.size() << std::endl;

        if (circles.size() == 0)
        {
            std::cout << "No circles were detected" << '\n';
            circlesExist = 0;
            circle[0] = 0;
            circle[1] = 0;
            circle[2] = 0;
        }
        else
        {
            for (size_t i = 0; i < circles.size(); i++)
            {
                //Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
                //int radius = cvRound(circles[i][2]);

                std::cout << "Circle Center - (x: " << circles[i][0] << "  y: " << circles[i][1] << ") and Radius: " << circles[i][2] << '\n';
                /*
                // circle center
                circle( BlurredImgCopy, center, 3, Scalar(0,255,0), -1, 8, 0 );
                // circle outline
                circle( BlurredImgCopy, center, radius, Scalar(0,0,255), 100, 8, 0 ); */
            }
        }
    }
}

And for Python:

import cv2
import cv2.cv as cv
import numpy
IMAGE_ROW = 1882

print "OpenCV version = ",cv2.__version__
FILENAME = '<path>/org5_6.bmp'

img = cv2.imread(FILENAME, 0)
print "Read image"
#cv2.imshow('img', img)
#cv2.waitKey(0) 

circle_exsit=1
[t_rows,t_cols]= img.shape
print 't_rows = ', t_rows
print 't_cols = ', t_cols
img=cv2.resize(img, (t_cols*IMAGE_ROW/t_rows,IMAGE_ROW))
img = cv2.medianBlur(img, 5)

[t_rows,t_cols]=img.shape
print 't_rows = ', t_rows
print 't_cols = ', t_cols

limit=min(t_rows,t_cols)
black_circle_radius_low=int(0.4*limit)
black_circle_radius_upper=int(0.45*limit)
print 'r_min = ',black_circle_radius_low
print 'rmax = ',black_circle_radius_upper

circles = cv2.HoughCircles(img,cv.CV_HOUGH_GRADIENT,1,300,param1=30,param2=30,minRadius=black_circle_radius_low,maxRadius=black_circle_radius_upper)
print circles

These codes are quite similar, but the results are different for C++ and Python -

Output from C++:

OpenCV Version = 2.4.11
Start HCircles..
t_cols : 3664
t_rows : 2748
After resizing
t_cols : 2509
t_rows : 1882
Radius min = 752
Radius max = 846
Total number of circles detected = 3
Circle Center - (x: 1325.5  y: 1094.5) and Radius: 759 ...
(more)