Ask Your Question

Uzzal's profile - activity

2017-03-18 18:34:15 -0600 received badge  Popular Question (source)
2014-08-07 01:37:48 -0600 commented question How to create a LBP histogram using OpenCV?

I want to create a lbp histogram

2014-08-06 21:08:20 -0600 asked a question How to create a LBP histogram using OpenCV?

I want to create a lbp histogram in OpenCV for a picture. Is there any change to create a lbp histogram? Hope for Help..

 #include "histogram.hpp"
 #include <vector>

template <typename _Tp>
void lbp::histogram_(const Mat& src, Mat& hist, int numPatterns) {
    hist = Mat::zeros(1, numPatterns, CV_32SC1);
    for(int i = 0; i < src.rows; i++) {
        for(int j = 0; j < src.cols; j++) {
            int bin = src.at<_Tp>(i,j);
            hist.at<int>(0,bin) += 1;
        }
    }
}

template <typename _Tp>
double lbp::chi_square_(const Mat& histogram0, const Mat& histogram1) {
    if(histogram0.type() != histogram1.type())
            CV_Error(CV_StsBadArg, "Histograms must be of equal type.");
    if(histogram0.rows != 1 || histogram0.rows != histogram1.rows || histogram0.cols != histogram1.cols)
            CV_Error(CV_StsBadArg, "Histograms must be of equal dimension.");
    double result = 0.0;
    for(int i=0; i < histogram0.cols; i++) {
        double a = histogram0.at<_Tp>(0,i) - histogram1.at<_Tp>(0,i);
        double b = histogram0.at<_Tp>(0,i) + histogram1.at<_Tp>(0,i);
        if(abs(b) > numeric_limits<double>::epsilon()) {
            result+=(a*a)/b;
        }
    }
    return result;
}


void lbp::spatial_histogram(const Mat& src, Mat& hist, int numPatterns, const Size& window, int overlap) {
    int width = src.cols;
    int height = src.rows;
    vector<Mat> histograms;
    for(int x=0; x < width - window.width; x+=(window.width-overlap)) {
        for(int y=0; y < height-window.height; y+=(window.height-overlap)) {
            Mat cell = Mat(src, Rect(x,y,window.width, window.height));
            histograms.push_back(histogram(cell, numPatterns));
        }
    }
    hist.create(1, histograms.size()*numPatterns, CV_32SC1);
    // i know this is a bit lame now... feel free to make this a bit more efficient...
    for(int histIdx=0; histIdx < histograms.size(); histIdx++) {
        for(int valIdx = 0; valIdx < numPatterns; valIdx++) {
            int y = histIdx*numPatterns+valIdx;
            hist.at<int>(0,y) = histograms[histIdx].at<int>(valIdx);
        }
    }
}

// wrappers
void lbp::histogram(const Mat& src, Mat& hist, int numPatterns) {
    switch(src.type()) {
        case CV_8SC1: histogram_<char>(src, hist, numPatterns); break;
        case CV_8UC1: histogram_<unsigned char>(src, hist, numPatterns); break;
        case CV_16SC1: histogram_<short>(src, hist, numPatterns); break;
        case CV_16UC1: histogram_<unsigned short>(src, hist, numPatterns); break;
        case CV_32SC1: histogram_<int>(src, hist, numPatterns); break;
    }
}

double lbp::chi_square(const Mat& histogram0, const Mat& histogram1) {
    switch(histogram0.type()) {
        case CV_8SC1: return chi_square_<char>(histogram0,histogram1); break;
        case CV_8UC1: return chi_square_<unsigned char>(histogram0,histogram1); break;
        case CV_16SC1: return chi_square_<short>(histogram0, histogram1); break;
        case CV_16UC1: return chi_square_<unsigned short>(histogram0,histogram1); break;
        case CV_32SC1: return chi_square_<int>(histogram0,histogram1); break;
    }
}

void lbp::spatial_histogram(const Mat& src, Mat& dst, int numPatterns, int gridx, int gridy, int overlap) {
    int width = static_cast<int>(floor(src.cols/gridx));
    int height = static_cast<int>(floor(src.rows / gridy));
    spatial_histogram(src, dst, numPatterns, Size_<int>(width, height), overlap);
}

// Mat return type functions
Mat lbp::histogram(const Mat& src, int numPatterns) {
    Mat hist;
    histogram(src, hist, numPatterns);
    return hist;
}


Mat lbp::spatial_histogram(const Mat& src, int numPatterns, const Size& window, int overlap) {
    Mat hist;
    spatial_histogram(src, hist, numPatterns, window, overlap);
    return hist;
}


Mat lbp::spatial_histogram(const Mat& src, int numPatterns, int gridx, int gridy, int overlap) {
    Mat hist;
    spatial_histogram(src, hist ...
(more)
2014-07-07 23:22:17 -0600 received badge  Scholar (source)
2014-07-07 23:22:13 -0600 received badge  Supporter (source)
2014-07-06 03:30:45 -0600 commented question Debug assertion failed in my visual studio 12 on windows 8.1. How can I fix it?

Yes, thank you its solved :)

2014-07-05 20:31:31 -0600 commented question Debug assertion failed in my visual studio 12 on windows 8.1. How can I fix it?

Then, have I changed my image path? Or what will I have to do?

2014-07-05 12:10:37 -0600 received badge  Editor (source)
2014-07-05 12:08:17 -0600 asked a question Debug assertion failed in my visual studio 12 on windows 8.1. How can I fix it?
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
/**
* @function main
*/
int main( int argc, char** argv )
{
    Mat src, dst;
    /// Load image
    src = imread( argv[1], 1 );
    if( !src.data )
    {
        return -1;
    }
    /// Separate the image in 3 places ( B, G and R )
    vector<Mat> bgr_planes;
    split( src, bgr_planes );
    /// Establish the number of bins
    int histSize = 256;
    /// Set the ranges ( for B,G,R) )
    float range[] = { 0, 256 } ;
    const float* histRange = { range };
    bool uniform = true; bool accumulate = false;
    Mat b_hist, g_hist, r_hist;
    /// Compute the histograms:
    calcHist( &bgr_planes[0], 1, 0, Mat(), b_hist, 1, &histSize, &histRange, uniform, accumulate );
    calcHist( &bgr_planes[1], 1, 0, Mat(), g_hist, 1, &histSize, &histRange, uniform, accumulate );
    calcHist( &bgr_planes[2], 1, 0, Mat(), r_hist, 1, &histSize, &histRange, uniform, accumulate );
    // Draw the histograms for B, G and R
    int hist_w = 512; int hist_h = 400;
    int bin_w = cvRound( (double) hist_w/histSize );
    Mat histImage( hist_h, hist_w, CV_8UC3, Scalar( 0,0,0) );
    /// Normalize the result to [ 0, histImage.rows ]
    normalize(b_hist, b_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat() );
    normalize(g_hist, g_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat() );
    normalize(r_hist, r_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat() );
    /// Draw for each channel
    for( int i = 1; i < histSize; i++ )
    {
        line( histImage, Point( bin_w*(i-1), hist_h - cvRound(b_hist.at<float>(i-1)) ) ,
                Point( bin_w*(i), hist_h - cvRound(b_hist.at<float>(i)) ),
                Scalar( 255, 0, 0), 2, 8, 0 );
        line( histImage, Point( bin_w*(i-1), hist_h - cvRound(g_hist.at<float>(i-1)) ) ,
                Point( bin_w*(i), hist_h - cvRound(g_hist.at<float>(i)) ),
                Scalar( 0, 255, 0), 2, 8, 0 );
        line( histImage, Point( bin_w*(i-1), hist_h - cvRound(r_hist.at<float>(i-1)) ) ,
                Point( bin_w*(i), hist_h - cvRound(r_hist.at<float>(i)) ),
                Scalar( 0, 0, 255), 2, 8, 0 );
    }
    /// Display
    namedWindow("calcHist Demo", CV_WINDOW_AUTOSIZE );
    imshow("calcHist Demo", histImage );
    waitKey(0);
    return 0;
}

image description

The code below is used for histogram calculation using Local Binary Pattern in Visual Studio when i try to run in visual studio 12 then it shows debug assertion failed. and see the image for details Hope for a solution

2014-07-05 00:30:16 -0600 commented answer when i tries to run simple code for OpenCV in Visual studio 12 it says many errors. How can i solve this

Is this for opencv C:\Opencv243\build\x86\vc10\bin

2014-07-04 17:41:46 -0600 commented answer when i tries to run simple code for OpenCV in Visual studio 12 it says many errors. How can i solve this

I am using windows 8.1

Thank You

Hope for a solution.

2014-07-04 12:13:29 -0600 asked a question when i tries to run simple code for OpenCV in Visual studio 12 it says many errors. How can i solve this
#include <opencv\cv.h>
#include <opencv\highgui.h>
using namespace cv;
int main()
{   // Create matrix to store.
    Mat image;
    // initializing capture
    VideoCapture cap;
    cap.open(0);
    //create window to show image
    namedWindow("window",1);
    // copy webcam stream to image
    cap>>image;
    //print image to screen
    imshow("window",image);
    // delay 33ms
    waitKey(33);
    }

and its errors are

'OpenCV.exe' (Win32): Loaded 'C:\Users\Uzzal Das\Documents\Visual Studio 2012\Projects\OpenCV\Debug\OpenCV.exe'. Symbols loaded.
'OpenCV.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Symbols loaded.
'OpenCV.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Symbols loaded.
'OpenCV.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Symbols loaded.
'OpenCV.exe' (Win32): Loaded 'C:\Opencv243\build\x86\vc10\bin\opencv_core243d.dll'. Cannot find or open the PDB file.
'OpenCV.exe' (Win32): Loaded 'C:\Opencv243\build\x86\vc10\bin\opencv_highgui243d.dll'. Cannot find or open the PDB file.
'OpenCV.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp110d.dll'. Symbols loaded.
'OpenCV.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcr110d.dll'. Symbols loaded.
'OpenCV.exe' (Win32): Loaded 'C:\Users\Uzzal Das\Documents\Visual Studio 2012\Projects\OpenCV\Debug\msvcp100d.dll'. Symbols loaded.
'OpenCV.exe' (Win32): Loaded 'C:\Users\Uzzal Das\Documents\Visual Studio 2012\Projects\OpenCV\Debug\msvcr100d.dll'. Symbols loaded.
'OpenCV.exe' (Win32): Loaded 'C:\Windows\SysWOW64\user32.dll'. Symbols loaded.
'OpenCV.exe' (Win32): Loaded 'C:\Windows\SysWOW64\gdi32.dll'. Symbols loaded.
'OpenCV.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ole32.dll'. Symbols loaded.
'OpenCV.exe' (Win32): Loaded 'C:\Windows\SysWOW64\oleaut32.dll'. Symbols loaded.
'OpenCV.exe' (Win32): Loaded 'C:\Windows\SysWOW64\advapi32.dll'. Symbols loaded.
'OpenCV.exe' (Win32): Loaded 'C:\Windows\SysWOW64\comctl32.dll'. Symbols loaded.
'OpenCV.exe' (Win32): Loaded 'C:\Windows\SysWOW64\avifil32.dll'. Symbols loaded.
'OpenCV.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvfw32.dll'. Symbols loaded.
'OpenCV.exe' (Win32): Loaded 'C:\Windows\SysWOW64\avicap32.dll'. Symbols loaded.
'OpenCV.exe' (Win32): Loaded 'C:\Windows\SysWOW64\combase.dll'. Symbols loaded.
'OpenCV.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcrt.dll'. Symbols loaded.
'OpenCV.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt4.dll'. Symbols loaded.
'OpenCV.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sechost.dll'. Symbols loaded.
'OpenCV.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winmm.dll'. Symbols loaded.
'OpenCV.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msacm32.dll'. Symbols loaded.
'OpenCV.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shell32.dll'. Symbols loaded.
'OpenCV.exe' (Win32): Loaded 'C:\Windows\SysWOW64\version.dll'. Symbols loaded.
'OpenCV.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sspicli.dll'. Symbols loaded.
'OpenCV.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winmmbase.dll'. Symbols loaded.
'OpenCV.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shlwapi.dll'. Symbols loaded.
'OpenCV.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptbase.dll'. Symbols loaded.
'OpenCV.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cfgmgr32.dll'. Symbols loaded.
'OpenCV.exe' (Win32): Loaded 'C:\Windows\SysWOW64\devobj.dll'. Symbols loaded.
'OpenCV.exe' (Win32): Loaded 'C:\Windows\SysWOW64\bcryptprimitives.dll'. Symbols loaded.
'OpenCV.exe' (Win32): Loaded 'C:\Windows\SysWOW64\imm32.dll'. Symbols loaded.
'OpenCV.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msctf.dll'. Symbols loaded.
'OpenCV.exe' (Win32): Loaded 'C:\PROGRA~2\SupTab ...
(more)