Ask Your Question

roylisto's profile - activity

2016-01-07 11:59:05 -0600 received badge  Popular Question (source)
2014-04-15 05:08:55 -0600 received badge  Student (source)
2014-04-13 17:46:42 -0600 asked a question moving object detection on aerial video with opencv

hy, i want to detect moving object in aerial video, the problem is camera also moving , so the background in the video is moving too. it's difficult to me to solve this problem, can anyone help me? here's my code until now

#include "stdafx.h"
#include "iostream"
#include "stdlib.h"

// OpenCV includes.
#include "cv.h"
#include "highgui.h"

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
        //Create a new window.
    cvNamedWindow("My Window", CV_WINDOW_AUTOSIZE);

    //Create a new movie capture object.
    CvCapture *input;

    //Assign the movie to capture.
    //inputMovie = cvCaptureFromAVI("vinoth.avi");

    char *fileName = "E:\\Tugas Akhir\\Video Master\\aerial.mp4";
    //char *fileName = "D:\\Profile\\AVI\\cardriving.wmv";
    input = cvCaptureFromFile(fileName);
    if (!input)
    {
        cout << "Can't open file" << fileName; }


    //Size of the image.
    /*CvSize imgSize;
    imgSize.width = 352;
    imgSize.height = 240;*/
    IplImage* frame = cvQueryFrame(input);
    CvSize imgSize = cvGetSize(frame); 

    //Images to use in the program.
    IplImage* greyImage = cvCreateImage( imgSize, IPL_DEPTH_8U, 1);
    IplImage* colourImage;
    IplImage* movingAverage = cvCreateImage( imgSize, IPL_DEPTH_32F, 3);
    IplImage* difference;
    IplImage* temp;
    IplImage* motionHistory = cvCreateImage( imgSize, IPL_DEPTH_8U, 3);

    //Rectangle to use to put around the people.
    CvRect bndRect = cvRect(0,0,0,0);

    //Points for the edges of the rectangle.
    CvPoint pt1, pt2;

    //Create a font object.
    CvFont font;


    //Create video to output to.
//  char* default_file[50] = "D:\\outputMovie.avi";
//  char* outFilename = argc==2 ? argv[1] : default_file; 
    //char* outFilename = argc==2 ? argv[1] : "D:\\outputMovie.avi";
    //char* outFilename[50]="D:\\outputMovie.avi";
    string default_filename="E:\\Tugas Akhir\\Video Master\\outputMovide.avi";
    //char* outFilename= default_filename.c_str();
    CvVideoWriter* outputMovie = cvCreateVideoWriter(default_filename.c_str(),
    CV_FOURCC('F', 'L', 'V', 'I'), 29.97, cvSize(720, 576));

    //Capture the movie frame by frame.
    int prevX = 0;
    int numPeople = 0;

    //Buffer to save the number of people when converting the integer
    //to a string.
    char wow[65];

    //The midpoint X position of the rectangle surrounding the moving objects.
    int avgX = 0;

    //Indicates whether this is the first time in the loop of frames.
    bool first = true;

    //Indicates the contour which was closest to the left boundary before the object
    //entered the region between the buildings.
    int closestToLeft = 0;
    //Same as above, but for the right.
    int closestToRight = 320;

    //Keep processing frames...
    for(;;)
    {
    //Get a frame from the input video.
    colourImage = cvQueryFrame(input);

    //If there are no more frames, jump out of the for.
    if( !colourImage )
    {
    break;
    }

    //If this is the first time, initialize the images.
    if(first)
    {
    difference = cvCloneImage(colourImage);
    temp = cvCloneImage(colourImage);
    cvConvertScale(colourImage, movingAverage, 1.0, 0.0);
    first = false;
    }
    //else, make a running average of the motion.
    else
    {
    cvRunningAvg(colourImage, movingAverage, 0.020, NULL);
    }

    //Convert the scale of the moving average.
    cvConvertScale(movingAverage,temp, 1.0, 0.0);

    //Minus the current frame from the moving average.
    cvAbsDiff(colourImage,temp,difference);

    //Convert the image to grayscale.
    cvCvtColor(difference,greyImage,CV_RGB2GRAY);

    //Convert the image to black and white.
    cvThreshold(greyImage, greyImage, 70, 255, CV_THRESH_BINARY);

    //Dilate and erode to get people blobs
    cvDilate(greyImage, greyImage, 0, 18);
    cvErode(greyImage, greyImage, 0, 10);

    //Find the contours of the moving images in the frame.
    CvMemStorage* storage = cvCreateMemStorage ...
(more)
2013-02-03 11:41:32 -0600 asked a question how to call bruteforcematcher

BruteForceMatcher

hai im using opencv 2.4.3 , and i'm try to call BruteForceMatcher , but i have error

this is my code

include "iostream"
include "vector"
include "opencv2/core/core.hpp"
include "opencv2/imgproc/imgproc.hpp"
include "opencv2/highgui/highgui.hpp"
include "opencv2/nonfree/features2d.hpp"
include "opencv2/features2d/features2d.hpp"

int main() { // Read input images cv::Mat image1= cv::imread("../gambar1.jpg",0); cv::Mat image2= cv::imread("../gambar2.jpg",0); if (!image1.data || !image2.data) return 0;

// Display the images
    cv::namedWindow("Right Image");
    cv::imshow("Right Image",image1);
    cv::namedWindow("Left Image");
    cv::imshow("Left Image",image2);

    // vector of keypoints
    std::vector<cv::KeyPoint> keypoints1;
    std::vector<cv::KeyPoint> keypoints2;

    // Construction of the SURF feature detector
    cv::SurfFeatureDetector surf(3000);

    // Detection of the SURF features
    surf.detect(image1,keypoints1);
    surf.detect(image2,keypoints2);

    std::cout << "Number of SURF points (1): " << keypoints1.size() << std::endl;
    std::cout << "Number of SURF points (2): " << keypoints2.size() << std::endl;

    // Draw the kepoints
    cv::Mat imageKP;
    cv::drawKeypoints(image1,keypoints1,imageKP,cv::Scalar(255,255,255),cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
    cv::namedWindow("Right SURF Features");
    cv::imshow("Right SURF Features",imageKP);
    cv::drawKeypoints(image2,keypoints2,imageKP,cv::Scalar(255,255,255),cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
    cv::namedWindow("Left SURF Features");
    cv::imshow("Left SURF Features",imageKP);

    // Construction of the SURF descriptor extractor
    cv::SurfDescriptorExtractor surfDesc;

    // Extraction of the SURF descriptors
    cv::Mat descriptors1, descriptors2;
    surfDesc.compute(image1,keypoints1,descriptors1);
    surfDesc.compute(image2,keypoints2,descriptors2);

    std::cout << "descriptor matrix size: " << descriptors1.rows << " by " << descriptors1.cols << std::endl;

    // Construction of the matcher
    BruteForceMatcher<cv::L2<float>> matcher;
    // Match the two image descriptors
    std::vector<cv::DMatch> matches;
    matcher.match(descriptors1,descriptors2, matches);

    std::cout << "Number of matched points: " << matches.size() << std::endl;

    std::nth_element(matches.begin(),    // initial position
                         matches.begin()+24, // position of the sorted element
                                     matches.end());     // end position
    // remove all elements after the 25th
    matches.erase(matches.begin()+25, matches.end());

    cv::Mat imageMatches;
    cv::drawMatches(image1,keypoints1,  // 1st image and its keypoints
                        image2,keypoints2,  // 2nd image and its keypoints
                                    matches,                        // the matches
                                    imageMatches,           // the image produced
                                    cv::Scalar(255,255,255)); // color of the lines
    cv::namedWindow("Matches");
    cv::imshow("Matches",imageMatches);

    cv::waitKey();
    return 0;

    int size=7;
    cv::Mat imaf1;
    image1.convertTo(imaf1,CV_32F);

    cv::Mat imaf2;
    image2.convertTo(imaf2,CV_32F);

    cv::waitKey();
    return 0;

}

and this is the error

1>------ Build started: Project: pixelTracking, Configuration: Debug Win32 ------ 1>Compiling... 1>main.cpp 1>d:\myproject\opencv\belajar\pixeltracking\pixeltracking\main.cpp(58) : error C2065: 'BruteForceMatcher' : undeclared identifier 1>d:\myproject\opencv\belajar\pixeltracking\pixeltracking\main.cpp(58) : error C2275: 'cv::L2<t>' : illegal use of this type as an expression 1> with 1> [ 1> T=float 1> ] 1>d:\myproject\opencv\belajar\pixeltracking\pixeltracking\main.cpp(58) : error C2065: 'matcher' : undeclared identifier 1>d:\myproject\opencv\belajar\pixeltracking\pixeltracking\main.cpp(61) : error C2065: 'matcher' : undeclared identifier 1>d:\myproject\opencv\belajar\pixeltracking\pixeltracking\main.cpp(61) : error C2228: left of '.match' must have class/struct/union 1> type ... (more)