2020-03-28 03:41:31 -0600
| received badge | ● Notable Question
(source)
|
2019-02-13 04:15:40 -0600
| received badge | ● Famous Question
(source)
|
2018-05-25 05:50:14 -0600
| received badge | ● Popular Question
(source)
|
2018-02-20 23:47:14 -0600
| received badge | ● Notable Question
(source)
|
2017-11-01 10:24:27 -0600
| received badge | ● Popular Question
(source)
|
2017-02-23 08:26:12 -0600
| commented answer | detcting colour of blobs |
2017-02-23 07:44:52 -0600
| commented answer | assertion failed error in kmeans |
2017-02-22 06:06:46 -0600
| commented answer | detcting colour of blobs i tried that too that doesn't work either and even if that was the problem green blobs would be detected as red and red as green ones but all the blobs were detected as red |
2017-02-21 09:59:05 -0600
| commented question | detcting colour of blobs somehow all the blobs are detected as red even green ones |
2017-02-21 09:55:00 -0600
| asked a question | detcting colour of blobs I am making a project that detects circles in a real time image and then classifies the circle as red or green. My approach towards the problem is that first i make a saliency map of the original image then i apply simple blob detector on that saliency map by setting suitable parameters.Hence the circles are detected as blobs .Then i extract the coordinates of the centre of th blob and go to that coordinate in the original 3 channel image , if the pixel value in the red channel is more than that in green it is classified as red otherwise green,but this logic fails to work i dont get why
my code: int main()
{
// Read image
Mat org=imread("32.jpg");
Mat im = imread( "sal12.jpg", IMREAD_GRAYSCALE );
Size s(400,300);
resize(im,im,s);
resize(org,org,s);
imshow("original",org);
imshow("saliency map",im);
// Setup SimpleBlobDetector parameters.
SimpleBlobDetector::Params params;
// Change thresholds
params.minThreshold = 10;
params.maxThreshold = 256;
// Filter by Area.
params.filterByArea = true;
params.minArea =70;
params.maxArea=1000;
// filter my min distance
//params.minDistBetweenBlobs=100;
// Filter by Circularity
params.filterByCircularity = true;
params.minCircularity = 0.8;
// Filter by Convexity
params.filterByConvexity = true;
params.minConvexity = 0.5;
// Filter by Inertia
params.filterByInertia = false;
params.minInertiaRatio = 0.01;
//filter by colour
params.filterByColor=false;
params.blobColor=255;
// Storage for blobs
vector<KeyPoint> keypoints;
// Set up detector with params
Ptr<SimpleBlobDetector> detector = SimpleBlobDetector::create(params);
// Detect blobs
detector->detect( im, keypoints);
//the total no of blobs detected are:
int x=keypoints.size();
cout<<"total no of circles detected are:"<< x <<endl;
cout<<endl;
int green=0;
int red=0;
for(int i=0;i<x;i++)
{
//location of first blob
Point2f point1=keypoints.at(i).pt;
int x1=point1.x;
int y1=point1.y;
float R=(float)org.at<Vec3b>(x1,y1)[1];
float B=(float)org.at<Vec3b>(x1,y1)[0];
float G=(float)org.at<Vec3b>(x1,y1)[2];
cout<<"location of "<<i+1<<" blob is "<<x1<<","<<y1<<endl;
cout<<" blue channel pixel value at the location is"<<(float)org.at<Vec3b>(x1,y1)[0]<<endl;
cout<<" green channel pixel value at the location is"<<(float)org.at<Vec3b>(x1,y1)[2]<<endl;
cout<<" red channel pixel value at the location is"<<(float)org.at<Vec3b>(x1,y1)[1]<<endl;
if (R>G)
{
cout<<" THE BLOB IS RED"<<endl;
red++;
}
if(G>R)
{
cout<<"THE BLOB IS GREEN"<<endl;
green++;
}
//cout<<"hue value : "<<(int)hsv.at<Vec3b>(x1,y1)[0]<<endl;
float size=keypoints.at(i).size;
cout<<"size of the blob is : "<<size<<cout<<endl;
cout<<endl;
}
cout<<"no of green circles: "<<green<<endl;
cout<<"no of red circles :"<<red <<endl;
//Draw detected blobs as red circles.
//DrawMatchesFlags::DRAW_RICH_KEYPOINTS flag ensures
// the size of the circle corresponds to the size of blob
Mat im_with_keypoints;
drawKeypoints(org, keypoints, im_with_keypoints, Scalar(0,0,255), DrawMatchesFlags::DRAW_RICH_KEYPOINTS );
} |
2017-02-18 03:18:42 -0600
| commented answer | x y cordinates of the blobs detected by simple blob detector how can i print the diameter of blob detected? and what does the octave parameter of the keypoint return? |
2017-02-18 02:56:09 -0600
| asked a question | x y cordinates of the blobs detected by simple blob detector i am running the sample code for simple blob detector in open cv 3 in c++ i want to print the x and y cordinate of the keypoints that are detected , here is the code: using namespace cv;
using namespace std; int main()
{ // Read image
Mat im = imread( "24.jpg", IMREAD_GRAYSCALE );
Size s(400,300);
resize(im,im,s);
imshow("original",im);
// Setup SimpleBlobDetector parameters.
SimpleBlobDetector::Params params;
// Change thresholds
params.minThreshold = 10;
params.maxThreshold = 256;
// Filter by Area.
params.filterByArea = true;
params.minArea =50;
params.maxArea=700;
// filter my min distance
//params.minDistBetweenBlobs=100;
// Filter by Circularity
params.filterByCircularity = true;
params.minCircularity = 0.8;
// Filter by Convexity
params.filterByConvexity = true;
params.minConvexity = 0.5;
// Filter by Inertia
params.filterByInertia = false;
params.minInertiaRatio = 0.01;
//filter by colour
params.filterByColor=true;
params.blobColor=255;
// Storage for blobs
vector<KeyPoint> keypoints;
// Set up detector with params
Ptr<SimpleBlobDetector> detector = SimpleBlobDetector::create(params);
// Detect blobs
detector->detect( im, keypoints);
//the total no of blobs detected are:
size_t x=keypoints.size();
cout<<"total no of circles detected are:"<<x<<endl;
//location of first blob
Point2f point1=keypoints.at(0).pt;
float x1=point1.x;
float y1=point1.y;
cout<<"location of the first blob is "<<x1<<","<<y1;
// Draw detected blobs as red circles.
// DrawMatchesFlags::DRAW_RICH_KEYPOINTS flag ensures
// the size of the circle corresponds to the size of blob
Mat im_with_keypoints;
drawKeypoints( im, keypoints, im_with_keypoints, Scalar(0,0,255), DrawMatchesFlags::DRAW_RICH_KEYPOINTS );
// Show blobs
imshow("keypoints", im_with_keypoints );
waitKey();
} |
2017-01-14 05:27:31 -0600
| commented answer | assertion failed error in kmeans thanks a lot sir and i just started using open cv 2 months back so i am new to the library and how it works the only way i learn is through internet i didnt write this code i found this code online only and was trying to understand and run it to learn how kmeans can be used to posterize an image |
2017-01-14 00:12:16 -0600
| asked a question | assertion failed error in kmeans i am trying to write a code to posterize an image using kmeans in open 3.0 (c++)
the code is as follows : int main()
{
Mat src = imread("1.jpg", 1 );
Mat samples(src.rows * src.cols, 3, CV_32F);
//Mat samples(3,src.rows*src.cols,CV_32F);
for( int y = 0; y < src.rows; y++ )
for( int x = 0; x < src.cols; x++ )
for( int z = 0; z < 3; z++)
samples.at<float>(y + x*src.rows, z) = src.at<Vec3b>(y,x)[z];
int clusterCount = 3;
Mat labels;
int attempts = 5;
Mat centers;
//kmeans(samples, clusterCount, labels, TermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS, 10000, 0.0001), attempts, KMEANS_PP_CENTERS, centers );
kmeans(samples,clusterCount, labels,TermCriteria( TermCriteria::EPS+TermCriteria::COUNT, 10, 1.0),3, KMEANS_RANDOM_CENTERS, centers);
Mat new_image(src.rows * src.cols, 3, CV_32S);
for( int y = 0; y < src.rows; y++ )
for( int x = 0; x < src.cols; x++ )
{
int cluster_idx = labels.at<int>(y + x*src.rows,0);
new_image.at<Vec3b>(y,x)[0] = centers.at<int>(cluster_idx, 0);
new_image.at<Vec3b>(y,x)[1] = centers.at<int>(cluster_idx, 1);
new_image.at<Vec3b>(y,x)[2] = centers.at<int>(cluster_idx, 2);
}
imshow( "clustered image", new_image );
waitKey();
}
i am getting an assertion failed error :
OpenCV Error: Assertion failed (N >= K) in cv::kmeans, file C:\buildslave64\win64_amdocl\master_PackSlave-win64-vc11-shared\opencv\modules\core\src\kmeans.cpp, line 231
how should i resolve this ? |
2017-01-07 05:19:56 -0600
| edited question | unable to include xml files in ergrouping function in erfilter ergrouping erfilter of text module of opencv i am trying to run the sample code for text detection present in the contrib module of opencv it uses erfilter to detect text on screen here is a youtube link the shows the working code https://www.youtube.com/watch?v=9Stvq... but i am unable to run the code due to an error in the function call of ergrouping which is a function of erfilter here is the function call erGrouping(src, channels, regions, region_groups, groups_boxes, ERGROUPING_ORIENTATION_ANY,"trained_classifier_erGrouping.xml", 0.5); documentation of the functions are available of the link below http://docs.opencv.org/3.0-beta/modul.... code is follows: using namespace std;
using namespace cv;
using namespace cv::text;
struct CV_EXPORTS ERStat
{
public:
//! Constructor
explicit ERStat(int level = 256, int pixel = 0, int x = 0, int y = 0);
//! Destructor
~ERStat() { }
//! seed point and threshold (max grey-level value)
int pixel;
int level;
//! incrementally computable features
int area;
int perimeter;
int euler; //!< euler number
Rect rect; //!< bounding box
double raw_moments[2]; //!< order 1 raw moments to derive the centroid
double central_moments[3]; //!< order 2 central moments to construct the covariance matrix
std::deque<int> *crossings;//!< horizontal crossings
float med_crossings; //!< median of the crossings at three different height levels
//! 2nd stage features
float hole_area_ratio;
float convex_hull_ratio;
float num_inflexion_points;
//! probability that the ER belongs to the class we are looking for
double probability;
//! pointers preserving the tree structure of the component tree
ERStat* parent;
ERStat* child;
ERStat* next;
ERStat* prev;
};
class CV_EXPORTS ERFilter : public Algorithm
{
public:
//! callback with the classifier is made a class.
//! By doing it we hide SVM, Boost etc. Developers can provide their own classifiers
class CV_EXPORTS Callback
{
public:
virtual ~Callback() { }
//! The classifier must return probability measure for the region.
virtual double eval(const CV_EXPORTS::ERStat& stat) = 0;
};
/*!
the key method. Takes image on input and returns the selected regions in a vector of ERStat
only distinctive ERs which correspond to characters are selected by a sequential classifier
*/
virtual void run( InputArray image, std::vector<CV_EXPORTS::ERStat>& regions ) = 0;
};
void show_help_and_exit(const char *cmd);
void groups_draw(Mat &src, vector<Rect> &groups);
void er_show(vector<Mat> &channels, vector<vector< CV_EXPORTS::ERStat> > ®ions);
int main()
{
namedWindow("grouping",WINDOW_NORMAL);
Mat src = imread("C:\\Users\\Shreya Srivastava\\Desktop\\UAS\\img\\IMG_276.jpg");
// Extract channels to be processed individually
vector<Mat> channels;
cv::text::computeNMChannels(src, channels);
int cn = (int)channels.size();
// Append negative channels to detect ER- (bright regions over dark background)
for (int c = 0; c < cn-1; c++)
channels.push_back(255-channels[c]);
// Create ERFilter objects with the 1st and 2nd stage default classifiers
Ptr<CV_EXPORTS::ERFilter> er_filter1 = createERFilterNM1(loadClassifierNM1("C:\\Program Files (x86)\\opencv_contrib-master\\modules\\text\\samples\\trained_classifierNM1.xml"),16,0.00015f,0.13f,0.2f,true,0.1f);
Ptr<CV_EXPORTS::ERFilter> er_filter2 = createERFilterNM2(loadClassifierNM2("C:\\Program Files (x86)\\opencv_contrib-master\\modules\\text\\samplestrained_classifierNM2.xml"),0.5);
vector<vector<CV_EXPORTS::ERStat> > regions(channels.size());
// Apply the default cascade classifier to each independent channel (could be done in parallel)
cout << "Extracting Class Specific Extremal Regions ... (more) |
2017-01-06 05:45:10 -0600
| commented question | digit recognition using ANN_MLP opencv 3.0 error can you explain me the what
nnPtr->setBackpropWeightScale(0.5f);
nnPtr->setBackpropMomentumScale(0.5f);
this will implement |
2017-01-06 03:41:03 -0600
| commented question | digit recognition using ANN_MLP opencv 3.0 error no its not the previous error i was debugging somehow if i cout<<trainLabels.rows; it gives me 4 instead of 35591 (which is equal to the no examples) |
2017-01-05 02:58:17 -0600
| received badge | ● Teacher
(source)
|
2017-01-05 01:22:53 -0600
| commented answer | Improve image preprocessing read this paper and try applying the method described i think it will solve your problem
:http://cmp.felk.cvut.cz/~cernyad2/TextCaptchaPdf/Detecting%20Text%20in%20Natural%20Scenes%20with%20Stroke%20Width%20Transform.pdf |
2017-01-04 09:28:22 -0600
| answered a question | Improve image preprocessing you should search for stroke width transform for text detection and try to segment characters by that method and then use ocr. can you provide a link to theinput image |
2017-01-04 05:05:35 -0600
| commented question | digit recognition using ANN_MLP opencv 3.0 error yes sir you are right i considered the no of rows instead of column i changed the code and made it 784 instead of 35591 but i am still getting errors that i am trying to resolve actually i am new to open cv and its confused |
2017-01-01 06:40:14 -0600
| received badge | ● Enthusiast
|
2016-12-30 13:30:56 -0600
| received badge | ● Supporter
(source)
|
2016-12-30 13:07:50 -0600
| commented question | digit recognition using ANN_MLP opencv 3.0 error |
2016-12-30 12:56:01 -0600
| commented question | digit recognition using ANN_MLP opencv 3.0 error |
2016-12-30 12:08:46 -0600
| commented question | digit recognition using ANN_MLP opencv 3.0 error the text version:
OpenCV Error Assertion failed (nvars==(int)rowvals.size()) in cv ml TrainDataImpl::loadCSV,file(then the path till ml/src/data.cpp,line 587 are you unable to view the images ? if so next time i will give the text version |
2016-12-30 11:31:12 -0600
| commented question | digit recognition using ANN_MLP opencv 3.0 error |
2016-12-30 10:40:00 -0600
| commented question | digit recognition using ANN_MLP opencv 3.0 error what method should be used for model selection of ann? like the no of layers and nodes?
is it hit and trial method and see maximum accuracy? |
2016-12-30 10:18:36 -0600
| commented question | digit recognition using ANN_MLP opencv 3.0 error vector<int> layerSizes;
layerSizes[0]=35591;
layerSizes[1]=1000;
layerSizes[2]=10;
most probably something wrong here |
2016-12-30 10:08:19 -0600
| commented question | digit recognition using ANN_MLP opencv 3.0 error |
2016-12-30 09:45:28 -0600
| marked best answer | how do i load and use TrainData I downloaded training set for digit recognition.
The training set is in csv format , the first column contains the responses and pixel value of the following response is stored the corresponding row.
I am trying to write a c++ code in visual studio that uses the ml module of open cv 3.00 to train from the data.
I can load the data using the TrainData::loadFromCSV function but i am unable to understand how will it generate the samples and responses matrix that is required to feed into the TrainData::create command
my code: void main()
{
TrainData::loadFromCSV("C:/Users/Shreya Srivastava/Desktop/train.csv",0,1,10);
Mat samples ( 28,28, CV_32FC1 );
Mat responses(35591,0,CV_32F);
TrainData::create(samples,ROW_SAMPLE,responses);
imshow("samples",samples);
waitKey();
}
|
2016-12-30 09:45:27 -0600
| commented answer | how do i load and use TrainData |
2016-12-30 09:44:22 -0600
| edited question | digit recognition using ANN_MLP opencv 3.0 error [C:\fakepath\csv file.png]
(/upfiles/1483124022567734.png)C:\fakepath\error.png C:\fakepath\error.pngthis related to the previous question i had asked:
http://answers.opencv.org/question/12...
i am trying to build digit recognition project using ANN_MLP open cv 3.0 and the code is as follows: C:\fakepath\csv file.png void main()
{
int inputLayerSize = 1;
int outputLayerSize = 1;
int numSamples = 2;
Mat layers = Mat(3, 1, CV_32S);
layers.row(0) =Scalar(35591) ;
layers.row(1) = Scalar(100);
layers.row(2) = Scalar(10);
vector<int> layerSizes;
layerSizes[0]=35591;
layerSizes[1]=1000;
layerSizes[2]=10;
Ptr<ANN_MLP> nnPtr =ANN_MLP::create();
//nnPtr->setLayerSizes(3);
nnPtr->setLayerSizes(layers);
nnPtr->setTrainMethod(ANN_MLP::BACKPROP);
nnPtr->setTermCriteria(TermCriteria(cv::TermCriteria::COUNT | cv::TermCriteria::EPS, 1000, 0.00001f));
nnPtr->setActivationFunction(ANN_MLP::SIGMOID_SYM, 1, 1);
nnPtr->setBackpropWeightScale(0.5f);
nnPtr->setBackpropMomentumScale(0.5f);
Ptr<TrainData> tdata = TrainData::loadFromCSV("C:/Users/Shreya Srivastava/Desktop/train.csv",
0, // lines to skip
0, // 1st elem is the label
-1); // only 1 response per line
Mat trainData = tdata->getTrainSamples();
Mat trainLabels = tdata->getTrainResponses();
int numClasses = 10; // assuming mnist
Mat hot(trainLabels.rows, numClasses, CV_32F, 0.0f); // all zero, initially
for (int i=0; i<trainLabels.rows; i++)
{
int id = (int)trainLabels.at<float>(i);
hot.at<float>(i, id) = 1.0f;
}
nnPtr->train(trainData,0,hot);
bool m = nnPtr->isTrained();
if (m)
std::cout << "training complete\n\n";
Ptr<TrainData> mdata = TrainData::loadFromCSV("C:/Users/Shreya Srivastava/Desktop/test.csv", 0,0,-1);
Mat testData = mdata->getTrainSamples();
Mat testLabels = mdata->getTrainResponses();
Mat testResults;
nnPtr->predict(testData, testResults);
float accuracy = float(countNonZero(testResults == testLabels)) / testLabels.rows;
printf("the accuracy is %f",accuracy);
}
i dont understand why i am getting assertion failed error |
2016-12-30 09:39:49 -0600
| received badge | ● Editor
(source)
|