Ask Your Question

Amit's profile - activity

2020-10-29 17:17:23 -0600 received badge  Famous Question (source)
2019-12-16 06:19:52 -0600 received badge  Popular Question (source)
2018-07-11 19:44:50 -0600 received badge  Notable Question (source)
2017-05-07 01:29:07 -0600 received badge  Popular Question (source)
2014-06-08 22:33:28 -0600 commented question count object in kalman filter

how, could u pls explain what need to change &/or modification...

2014-06-07 02:59:41 -0600 asked a question count object in kalman filter

In kalman filter, how to count detected object in sequence and is there any easiest way to ignore nearest object. MOG will provide good BG subtraction but it will work only for object near to cam.

using namespace std;
using namespace cv;

 #define drawCross( img, center, color, d )\
 line(img, Point(center.x - d, center.y - d), Point(center.x + d, center.y + d), color, 2, CV_AA, 0);\
 line(img, Point(center.x + d, center.y - d), Point(center.x - d, center.y + d), color, 2, CV_AA, 0 )\

int main()
{
Mat frame, thresh_frame,src_gray;
vector<Mat> channels;
VideoCapture capture;
vector<Vec4i> hierarchy;
vector<vector<Point> > contours;
  char text[255];
  int num = 0;
  BackgroundSubtractorMOG2 mog;
  capture.open("vid.avi");

  if(!capture.isOpened())
  cerr << "Problem opening video source" << endl;

   KalmanFilter KF(4, 2, 0);
   Mat_<float> state(4, 1);
   Mat_<float> processNoise(4, 1, CV_32F);
   Mat_<float> measurement(2,1); measurement.setTo(Scalar(0));

   KF.statePre.at<float>(0) = 0;
   KF.statePre.at<float>(1) = 0;
   KF.statePre.at<float>(2) = 0;
   KF.statePre.at<float>(3) = 0;

   KF.transitionMatrix = *(Mat_<float>(4, 4) << 1,0,1,0,   0,1,0,1,  0,0,1,0,  0,0,0,1); //  Including velocity
   KF.processNoiseCov = *(cv::Mat_<float>(4,4) << 0.2,0,0.2,0,  0,0.2,0,0.2,  0,0,0.3,0,  0,0,0,0.3);

   setIdentity(KF.measurementMatrix);
   setIdentity(KF.processNoiseCov, Scalar::all(1e-4));
   setIdentity(KF.measurementNoiseCov, Scalar::all(1e-1));
   setIdentity(KF.errorCovPost, Scalar::all(.1));

   while((char)waitKey(100) != 'q' && capture.grab())
   {
    capture.retrieve(frame);
    mog(frame,src_gray,-1);

    threshold( src_gray, thresh_frame, 128, 255, THRESH_BINARY );
    medianBlur(thresh_frame,thresh_frame,9);
    erode(thresh_frame,thresh_frame,Mat());
    dilate(thresh_frame,thresh_frame,Mat());
    imshow("MOG", thresh_frame);
    findContours( thresh_frame, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );

     Mat drawing = Mat::zeros(thresh_frame.size(), CV_8UC1);
     for(size_t i = 0; i < contours.size(); i++)
     {
     // cout << contourArea(contours[i]) << endl;
      if(contourArea(contours[i]) > 500)
        drawContours(drawing, contours, i, Scalar::all(255), CV_FILLED, 8, vector<Vec4i>(), 0, Point());

    }
  thresh_frame = drawing;

  vector<Moments> mu(contours.size() );
  for( size_t i = 0; i < contours.size(); i++ )
    { mu[i] = moments( contours[i], false ); }

  //  Get the mass centers:
  vector<Point2f> mc( contours.size() );
  for( size_t i = 0; i < contours.size(); i++ )
    { mc[i] = Point2f( mu[i].m10/mu[i].m00 , mu[i].m01/mu[i].m00 ); }

  Mat prediction = KF.predict();
  Point predictPt(prediction.at<float>(0),prediction.at<float>(1));

  for(size_t i = 0; i < mc.size(); i++)
    {
       cout << "\n" << mc.size();
       sprintf(text, "%d", num);
       putText(frame, text, mc[i],FONT_HERSHEY_COMPLEX_SMALL, 0.8, cvScalar(0,255,255), 1, CV_AA);
      measurement(0) = mc[i].x;
      measurement(1) = mc[i].y;
    }

  Point measPt(measurement(0),measurement(1));

  Mat estimated = KF.correct(measurement);
  Point statePt(estimated.at<float>(0),estimated.at<float>(1));

  drawCross(frame, statePt, Scalar(255, 255, 255), 5);

  KF.statePre.copyTo(KF.statePost);

  vector<vector<Point> > contours_poly( contours.size() );
  vector<Rect> boundRect( contours.size() );
  for( size_t i = 0; i < contours.size(); i++ )
   { approxPolyDP( Mat(contours[i]), contours_poly[i], 3, true ...
(more)
2014-05-29 08:41:09 -0600 answered a question Problem with russian letters

Actually Window can not recognize the name of folder in russian language,(if your window default language is in English)

for test i create a folder with name "Видео" and in command it show "????"(check screenshot)

image description

2014-05-27 06:24:50 -0600 answered a question Which IP camera more suitable for my project

use the following software to check the focal length, distance, etc parameter for IP based camera. Software name: IP Design Tool Setup

2014-04-26 23:50:08 -0600 answered a question Help! Installation of OpenCV

Use Codeblock IDE for coding (Alternative of Visual Studio) and for opencv library intergration use Following Link. This is the Simplest way to use Opencv features & explore it....

2014-04-26 23:31:16 -0600 commented question Cascade classifier, few questions

To train perfect, STAGES should be as high as possible. if you trained the object with 30 to 40 stages this will provide the perfect detection.

2014-04-26 23:20:40 -0600 commented question algorithm to detect only slow moving object

use Tracking (like Kalman, KLT) and/or find the centroid & track only moving/change pixel value on centroid.

2014-04-25 02:02:54 -0600 answered a question Deer Detection

Use Haar cascade classifier training and generate xml file, this will find the deer very easily, here is the demo on face detection using haar cascade Link

2014-04-24 08:21:50 -0600 commented question Direction of Vehicle

@steven i successfully implemented the KLTTracking, & able to track each vehicle. There are some minor issue but i handle them, Thanks for reply and good luck..

2014-04-22 23:21:56 -0600 commented question Direction of Vehicle

Yes, i done that, but inbetween with multiple vehicle (in same direction) the centroid will overlab.. Y:125 Y:129 Y:135 Y:75 Y:59 Y:62

2014-04-22 09:19:12 -0600 commented question Direction of Vehicle

Vow! how u do that(Nice Animation), but i already using optical flow with Lucas-Kanade method, in this i stuck on multiple vehicle. Can we find the direction using centriod (on multiple vehicle)....

2014-04-22 04:47:24 -0600 received badge  Student (source)
2014-04-22 01:53:51 -0600 asked a question Direction of Vehicle

How to Identify the direction of vehicle in up or down direction,

(1) i am able to detect vehicle with its centriod. image description

2014-04-03 02:30:26 -0600 received badge  Self-Learner (source)
2014-04-02 23:45:28 -0600 answered a question how to Ignore bounding box inside bounding box

Well, thanks haris for a new concept(really useful), but i use Steven code ie

    int cmin= 50;
    int cmax= 1000;        
    vector<vector<Point> >::iterator itc=contours.begin();
    while (itc!=contours.end()) {
            if (itc->size() < cmin || itc->size() > cmax){
                itc= contours.erase(itc);}
            else{
            vector<Point> pts = *itc;
            Mat pointsMatrix = Mat(pts);
            Scalar color( 0, 255, 0 );          
            Rect r0= boundingRect(pointsMatrix);
            rectangle(threshold_output,r0,color,2);

above sample code will solve my issue. But @Haris and @steven thanks for immediate reply & good luck

2014-03-31 23:48:30 -0600 commented question how to Ignore bounding box inside bounding box

Ah confused, can you provide some link or code(rough code).

2014-03-31 07:23:55 -0600 asked a question how to Ignore bounding box inside bounding box

when i draw the bounding box with centriod, i got the bounding box inside bounding box like this

bounding box

Actually i want to ignore the inner bounding box in all my bounding box.

I am using below code with ignoring all circles. link

2014-03-02 22:42:39 -0600 answered a question Image Crop

croping should be done by this method in C++, i got accurate croping image.

Rect roi(r.x, r.y, r.width, r.height);
Mat image_roi = image(roi);
image_roi.copyTo(cropimage);
imwrite("cropimage.jpg",image_roi);
2014-03-02 22:23:30 -0600 received badge  Editor (source)
2014-03-02 22:21:57 -0600 answered a question OpenCV ip camera

hi use port also like this..

camera.open("rtsp://192.168.1.110:554/live.sdp");

use your IP address in place of 192.168.1.110

2014-03-02 22:14:52 -0600 answered a question need help for object tracking

Use haartraining cascade classifier for hand detection, and for counting try number of frames per seconds.

2014-02-26 22:46:51 -0600 commented answer how to save current frame and previous frame

thanks hristov, its working.... good day.......

2014-02-26 22:45:58 -0600 received badge  Scholar (source)
2014-02-26 00:09:59 -0600 asked a question how to save current frame and previous frame

i want to save the current frame and previous frame in some directory from video in opencv. i am using C++ and opencv 2.4.8 library.

2014-01-29 23:37:08 -0600 commented answer haartraining counting

Thanks, first i will transform my code then I will look into this and get back to you

2014-01-29 07:18:31 -0600 asked a question haartraining counting

i used haartraininng to count the object, but this will count frame by frame. So can we use this to count a object one time only.

for( i = 0; i < (object ? object->total : 0); i++ )
                {
                    CvRect* r = (CvRect*)cvGetSeqElem( object, i );

                    pt1.x = r->x*scale;    
                    pt2.x = (r->x+r->width)*scale;
                    pt1.y = r->y*scale;
                    pt2.y = (r->y+r->height)*scale;

                    cvRectangle( img, pt1, pt2, CV_RGB(230,20,232), 3, 8, 0 );

                }
                cout << "Total: " << object->total << " cars" << endl;
2013-10-21 01:00:32 -0600 commented question cvblob error in Window IDEs

Well cvblob ( http://code.google.com/p/cvblob/ ) which is the opencv opensource library, which will detect any object as shown in red object detection is used by some experts, but while running this above error shown..but while compiling or building it didn't show any error....

2013-10-18 01:49:51 -0600 asked a question cvblob error in Window IDEs

When i m compiling cvblob "red object detection example" i a getting following error in Visual studio 2012, CODE BLOCK IDE, NETBEAM IDE.

...test1/source.cpp:50: undefined reference to `cvLabel',

...test1/source.cpp:52: undefined reference to `cvRenderBlobs',

...test1/source.cpp:54: undefined reference to `cvFilterByArea'

After compiling i m not getting any error, but After running the program i m facing above error i m using opencv 2.4.6 also tryed with opencv 2.4.2 Eveery opencv code is running in above IDE but blob give an error WHY...?????????