Ask Your Question

KirtiSwagat's profile - activity

2019-10-31 16:29:48 -0600 received badge  Notable Question (source)
2019-03-15 08:38:24 -0600 received badge  Popular Question (source)
2018-03-13 04:33:13 -0600 received badge  Famous Question (source)
2017-10-01 16:59:29 -0600 received badge  Notable Question (source)
2017-07-09 02:52:44 -0600 received badge  Popular Question (source)
2017-02-23 06:08:43 -0600 asked a question How to Visulaize HOG features with Original Image?

After calculation of HOG features. How to visualize these features with original image using Opencv?

2016-12-20 08:53:55 -0600 received badge  Student (source)
2016-12-19 05:39:18 -0600 answered a question [OpenCV]How to detect and connect camera automatically
VideoCapture capture(0);

if(!capture.isOpened())
{
return (-1);
}
double width= capture.get(CV_CAP_PROP_FRAME_WIDTH);//u can get the width of the frame
double height= capture.get(CV_CAP_PROP_FRAME_HEIGHT);;//u can get the height of the frame
Mat Frame;
for( ; ; )
{
capture>> Frame;
if(!Frame.empty())
{
do what ever u want with the captured frames
}
if(waitKey(30) == 27)//since esc key ASCII Value is 27 and if it is pressed for 30 ms it will stop the camera
{
cout<<"Esc key is pressed"<<endl;
break;
}

By default set the device Id= 0. So that automatically it will detect the camera.

2016-12-19 05:22:38 -0600 answered a question How to use HOG Descriptor ?
#include <opencv2/core/core.hpp>

#include <opencv2/highgui/highgui.hpp>
#include <opencv2/gpu/gpu.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/contrib/contrib.hpp>

Use these headers for your Problem.

2016-12-19 05:14:21 -0600 answered a question How to calculate Euclidean Distance d(h,g)
#include <opencv2/highgui/highgui.hpp>

#include <opencv2/core/core.hpp>
#include <opencv2/opencv.hpp>

#include <opencv2/imgproc/imgproc.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat Image1= imread("first.jpg",1);// 1 for default color space assume here B,G, R color space
Mat Image2=imread("second.jpg",1);
vector<Mat> planes_for_first_image;//Vector of Matrix created to hold the channels present in the input image
vector<Mat> planes_for_second_image;
split(Image1, planes_for_first_image);//Channels are separated here and stored in the vector of Matrix.
split(Image2, planes_for_second_image);
int histSize= 256;
int histHeight= 400;
int histWidth= 512;
int binWidth= cvRound((double)histWidth/histHeight);
Mat histImage= (histHeight, histWidth, CV_8UC3, scalar(0,0,0));
float range[]={0, 256};
const float* histRange= { range };
bool uniform= true;
bool accumulate= false;
Mat BlueHist1; Mat BlueHist2; // Matrix Declared to hold plane wise histogram
Mat GreenHist1; Mat GreenHist2;
Mat RedHist1; Mat RedHist2;
calHist(&planes_for_first_image)[0],1,0, Mat(), BlueHist1,1, &histSize, &histRange, uniform, accumulate);//histogram calculation for first image:- Blue Plane
calHist(&planes_for_first_image)[1],1,0, Mat(), GreenHist1,1, &histSize, &histRange, uniform, accumulate);//histogram calculation for first image:- Green Plane
calHist(&planes_for_first_image)[2],1,0, Mat(), RedHist1,1, &histSize, &histRange, uniform, accumulate);//histogram calculation for first image:- Red Plane



calHist(&planes_for_second_image)[0],1,0, Mat(), BlueHist2,1, &histSize, &histRange, uniform, accumulate);//histogram calculation for second image:- Blue Plane
calHist(&planes_for_second_image)[1],1,0, Mat(), GreenHist2,1, &histSize, &histRange, uniform, accumulate);//histogram calculation for second image:- Green Plane
calHist(&planes_for_second_image)[2],1,0, Mat(), RedHist1,1, &histSize, &histRange, uniform, accumulate);//histogram calculation for second image:- Red Plane


normalize(BlueHist1, BlusHist1, 0,histImage.rows, NORM_MINIMAX, -1, Mat() );
normalize(GreenHist1, GreenHist1, 0,histImage.rows, NORM_MINIMAX, -1, Mat() );
normalize(RedHist1, RedHist1, 0,histImage.rows, NORM_MINIMAX, -1, Mat() );

normalize(BlueHist2, BlusHist2, 0,histImage.rows, NORM_MINIMAX, -1, Mat() );
normalize(GreenHist2, GreenHist2, 0,histImage.rows, NORM_MINIMAX, -1, Mat() );
normalize(RedHist2, RedHist2, 0,histImage.rows, NORM_MINIMAX, -1, Mat() );

float distance_blue_plane= compareHist(BlueHist1, BlueHist2, CV_COMP_BHATTACHARYYA);// Histogram can be compared with Bhattacharyya distance or Chisqure or Correl or Hellinger or intersect use can use any one of these
float distance_green_plane= compareHist(GreenHist1, GreenHist2, CV_COMP_CHISQR);//I am just giving examples u can use any one .
float distance_red_place= compareHist(RedHist1, RedHist2, CV_COMP_CORREL);

cout<<distnace_blue_plane<<endl;
cout<<distance_green_plane<<endl;
cout<<distance_red_plane<<endl;



return 0;
}

I think for histogram comparison these method for distance calculations are better than Euclidean distance. If I am wrong please update me.

2016-12-19 04:19:46 -0600 received badge  Supporter (source)
2016-12-16 07:06:37 -0600 commented answer How to use LBP to visualize results ?

@break Thank you very much... :-)

2016-12-16 05:56:00 -0600 answered a question How to use LBP to visualize results ?
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/objdetect/objdetect.hpp>
#include <limits.h>
#include <math.h>
#include <iostream>


using namespace std;
using namespace cv;

Mat LBP(Mat src_image)
{
    bool value=true;
    Mat Image(src_image.rows, src_image.cols, CV_8UC1);
    Mat lbp(src_image.rows, src_image.cols, CV_8UC1);

    if (src_image.channels() == 3)
        cvtColor(src_image, Image, CV_BGR2GRAY);

    unsigned center = 0;
    unsigned center_lbp = 0;

    for (int row = 1; row < Image.rows-1; row++)
    {
        for (int col = 1; col < Image.cols-1; col++)
        {
            center = Image.at<uchar>(row, col);
            center_lbp = 0;

            if (center <= Image.at<uchar>(row-1, col-1))
                center_lbp += 1;

            if (center <= Image.at<uchar>(row-1, col))
                center_lbp += 2;//2

            if (center <= Image.at<uchar>(row-1, col+1))
                center_lbp += 4;//4

            if (center <= Image.at<uchar>(row, col+1 ))
                center_lbp += 8;//8

            if (center <= Image.at<uchar>(row+1, col+1))
                center_lbp += 16;//16

            if (center <= Image.at<uchar>(row+1, col))
                center_lbp += 32;//32

            if (center <= Image.at<uchar>(row+1,col-1))
                center_lbp += 64;//64

            if (center <= Image.at<uchar>(row,col-1))
                center_lbp += 128;//128
            lbp.at<uchar>(row, col) = center_lbp;
        }
    }

    if(value == true)
    {
        namedWindow( "image LBP", CV_WINDOW_FREERATIO);
        imshow("image_LBP", lbp);
        imwrite("/root/Desktop/LBP.jpg",lbp);
        waitKey(0);
        imshow("grayscale",Image);
        waitKey(0);
    }
    else
    {
      cv::destroyWindow("image LBP");
      cv::destroyWindow("grayscale");
    }

    return lbp;

}

int main()
{
    string filename="1.jpg";
    Mat frame1;
    frame1= imread("/root/Desktop/"+filename);
    LBP(frame1);
}

image description image description

2016-12-16 03:56:19 -0600 commented answer How to start with neural network implementation with Opencv and C++??

@berak Thank you for your suggestion.. Waiting for some sample code.

2016-12-16 02:55:48 -0600 asked a question How to start with neural network implementation with Opencv and C++??

I want to train for face Recognition Problem. I want to test it with Neural Network and want to compare it with the result obtained from PCA+SVM.

Problem is some how like this:-

  1. 4 persons . I have to train the NN with 6 sample images for each person.
  2. Each person's having 40 images. I have to cross check for recognition.
  3. Output should be respective class no or name. But for new person output should be another class/ new person.

As I am new to this NN. Please provide me some link or Sample Code. So that I can start with it..

2016-12-09 01:06:07 -0600 received badge  Enthusiast
2016-12-05 06:29:21 -0600 commented question How to read sequentially image files in OpenCv and C++

@berak how to do??? is there any modification required in my code.plz suggest

2016-12-05 06:12:18 -0600 edited question How to read sequentially image files in OpenCv and C++

Suppose I have 7 numbers of ".jpg" files in a folder. All the names are numeric that is 0.jpg, 4.jpg, 1.jpg etc. How to read the files sequentially according to there name incrementally. That is first 0.jpg then 1.jpg then 4.jpg will be read.

I have tried with glob( ) function but image read is not sequentially..

#include <opencv2/opencv.hpp>
#include<iostream>
#include <dirent.h> 
using namespace std;
using namespace cv;
int main()
{
String folder = "*.jpg";
 vector<String> filenames;
 glob(folder, filenames);
 cout<<filenames.size()<<endl;//to display no of files

  for(size_t i=0; i<filenames.size(),++i)
  {
  cout<<filenames[i]<<endl;
   }

}

and the output is as follows 7 // no of files in the folder ./0.jpg ./11.jpg ./14.jpg ./2.jpg ./6.jpg ./8.jpg ./9.jpg

2016-12-05 06:12:18 -0600 received badge  Editor (source)