Ask Your Question

José Jácome's profile - activity

2020-06-21 12:29:25 -0600 commented question Missing link for dictnet_vgg

Hi @Berak, thank you for your answer, I'm looking for a text recognition CNN example like the text_end_to_end_recognitio

2020-06-21 08:16:47 -0600 received badge  Student (source)
2020-06-21 07:05:14 -0600 asked a question Missing link for dictnet_vgg

Missing link for dictnet_vgg Hi everyone, I was testing the OpenCV Contrib samples of the text module. Regarding to the

2017-07-20 23:05:47 -0600 received badge  Enthusiast
2017-07-15 19:30:19 -0600 asked a question Segmentation of Plants on the Ground

Hi, to all

I want to develop a program to count plants in a crop, I have used some methods for segment the plants of the ground in OpenCV like inRange of HSV, Green Channel Segmentation and Histogram Backprojection but I have still some issues to get the total shape of the plants.

I tested my algorithm with the following images in some lighting conditions image description

For the HSV Segmentation I use four regions to get the Max and Min Values for each mask, so I sum the four masks of each segmentation to obtain an total mask, for the Green Channel Segmentation I split the channels of the BGR image and I apply the following equation to get the final mask T = 2*G - R - G, I also experimented normalizing the Green Channel to get better results in more light conditions and I apply the same equation, also I backproject the HS Histogram with a Sample of Color of a Plant and a Mask of that Plant(included in the images of the link at the bottom), so I get the following results

image description (In this case the HSV segmentation was the best, but in the next images Normalized Green Channel have better results)

My question is, is there any another method to rightly segment the plants? or how can I improve my code? I will appreciate every response, Link to Images

#include <iostream>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/videoio.hpp>

using namespace std;
using namespace cv;

String rutavideo;
Mat imagen;
int opcion = 0;
char c;
vector<Mat> canalesnorm(3);
vector<Mat> canales(3);
//Matrices para HSV
Mat procesado, procesadohsv;
//Matrices Procesamiento HSV
Mat verdenorm, azulnorm,rojonorm, normalizada, b1, b2, b3, b4;
//Matrices Procesado Capa Verde
Mat verdenormal;
//Matrices para Backprojection
Mat roi, mascararoi, roihsv;
//Procesado Capa Verde Normalizado
Mat verdenormalizado;
//Mascaras salida Colores
Mat mascarahsv, mascaranormal, mascaranormalizada, mascarabackprojection;
Mat ecualizado;
int h_bins = 26; int s_bins = 200;
int bins = 7;

int main(int argc, char *argv[])
{
    cout << "Parameters:" << endl;
    cout << "1.- Original Image" << endl;
    cout << "2.- Image of color of the plant" << endl;
    cout << "3.- Mask of 2" << endl;

    if(argc < 4)
    {
        cout << argv[0] << endl;
        cout << argv[1] << endl;
        cout << argv[2] << endl;
        cout << argv[3] << endl;

        cout << "Error, ingrese un numero valido de parametros" << endl;
        return -1;
    }
    imagen = imread(argv[1],IMREAD_COLOR);
    if(imagen.empty()){
        cout << "No hay imagen para segmentar, escriba una ruta valida" << endl;
        return -1;
    }
    //Codigo backprojection
    roi = imread(argv[2],IMREAD_COLOR);
    if(roi.empty()){
        cout << "No hay imagen patron de verde, escriba una ruta valida" << endl;
        return -1;
    }
    mascararoi = imread(argv[3],IMREAD_GRAYSCALE);
    if(mascararoi.empty()){
        cout << "No hay imagen de la mascara, escriba una ruta valida" << endl;
        return -1;
    }
    MatND histograma;
    MatND Backprojection;
    const int channels[] = {0, 1};      //Canal Hue y Canal Saturation
    if(bins < 1) bins = 1;
    int histSize[] = { h_bins, s_bins };
    const float rangohue[] = {0, 179};
    const float rangosaturation[] = {0, 255};
    const float* ranges[] = {rangohue, rangosaturation};
    cvtColor(roi,roihsv,COLOR_BGR2HSV);
    //Codigo Segmentacion HSV
    medianBlur ...
(more)
2017-02-20 15:50:12 -0600 received badge  Scholar (source)
2017-02-19 22:06:03 -0600 commented answer Problems with training a two output layer ANN_MLP from a CSV File

Thanks so much, it works! I modified the csv file and I used the first Code! It works Now.... A final question, for a ten layer ANN_MLP I should add the responses as for 0 0,1,2,3,4,5,6,7,8,9 for 1 1,2,3,4,5,6,7,8,9,0 . . . for 9 9,0,1,2,3,4,5,6,7,8 etc.?

2017-02-15 19:21:39 -0600 received badge  Editor (source)
2017-02-15 17:48:08 -0600 asked a question Problems with training a two output layer ANN_MLP from a CSV File

Hi, I'm trying to train a ANN_MLP with two layer output, I generated a CVS file and I read it with the function TrainData::loadFromCSV() , I have the following CSV file for recognize number 1 and 0:

0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,1
1,1,1,1,1,0,0,1,1,0,0,1,,1,1,1,1,0

In Opencv2 I noticed that at the final of the line de CSV files have a ;, but in the function loadFromCSV() it seams that the output argument is a one-dimmension array

That's my sample code

#include <iostream>
#include <opencv2/ml.hpp>

using namespace std;
using namespace cv;
using namespace cv::ml;

int main(int argc, char *argv[])
{
    Ptr<ANN_MLP> nnetwork = ANN_MLP::create();
    cout << "Leyendo Datos" << endl;
    Ptr<TrainData> datos = TrainData::loadFromCSV("/home/josejacomeb/QT/MLP_DosCapas/mlp_2capas.csv",ROW_SAMPLE);
    vector<int> layerSizes = { 16, //Numero de Entradas
                               32,   //Capa Oculta
                               2  //Capa de Salida, para 2 Numeros
                             };
    cout << datos->getSamples()<< endl;
    nnetwork->setLayerSizes(layerSizes);
    nnetwork->setActivationFunction(ANN_MLP::SIGMOID_SYM,0.6,1);
    //Entrenamiento
    nnetwork->setTermCriteria(TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS,100000,0.0000001));
    nnetwork->setTrainMethod(ANN_MLP::BACKPROP);
    cout << "Creando la RNA" << endl;
    nnetwork->train(datos);
    printf( "Entrenado \n");
    FileStorage fs("/home/josejacomeb/QT/MLP_DosCapas/parametros.xml",FileStorage::WRITE);
    nnetwork->write(fs);
    fs.release();
    cout << "Escribiendo XML" << endl;
}

So I've got the following error:

Opencv Error: Bad argument (output training data should be a floating-point matrix with  the number of rows equal to the number of training samples and the number of columns equal to the size of last (output) layer) in prepare_to_train, file /build/opencv/src/opencv-3.2.0/modules/ml/src/ann_mlp.cpp

I read in this forum that:

the train responses for an ann differ a bit from the usual opencv ml approach. if have 2 output neurons in your ann, need 2 output neurons for each training feature too, not a single "class label" (like with e.g. an SVM).

How can I create a 2 dimmension array from TrainData::loadFromCSV() for train the ANN_MLP?

I use Opencv 3.2 and GCC6