Ask Your Question

Revision history [back]

Video capture and search for a image in a database.....WARNING

We would like to capture a video over the webcam (in real time) and then search for QR code and compare the code that we have found with a database of QR codes.

include "opencv2/calib3d/calib3d.hpp"

include "opencv2/nonfree/nonfree.hpp"

include "opencv2/core/core.hpp"

include "opencv2/features2d/features2d.hpp"

include <opencv2 highgui="" highgui.hpp="">

include <opencv2 imgproc="" imgproc.hpp="">

include <windows.h>

include <iostream>

include <stdio.h>

include <legacy\legacy.hpp>

include <cxcore.h>

using namespace cv; using namespace std;

void readme();

/* @function main */ int main(int argc, char argv[]) {

VideoCapture cam(1);

cam.set(CV_CAP_PROP_FRAME_HEIGHT, 240);
cam.set(CV_CAP_PROP_FRAME_WIDTH, 320);

cv::Mat frames, frames_1;
cv::Mat grayIm, grayIm_1;
double FPS = 0.;
double FPS_sum = 0.;
int FPS_count = 0;
long prevTick = 0;
int count = 0;
char str[256] = { '\0' };


Mat img_1 = imread("C:\\Users\\Sony\\Desktop\\slika_1.jpg", CV_LOAD_IMAGE_GRAYSCALE);



std::vector<KeyPoint> keypoints_1;

////

cam >> frames_1;
grayIm.create(frames_1.rows, frames_1.cols, frames_1.type());

cv::Ptr<cv::FeatureDetector> test_1 = cv::FeatureDetector::create("FAST");

////



std::vector<cv::KeyPoint> keyp;

if (!cam.isOpened())
    return -1;

cam >> frames;
grayIm.create(frames.rows, frames.cols, frames.type());

cv::Ptr<cv::FeatureDetector> test = cv::FeatureDetector::create("FAST");


while (cv::waitKey(1) != 27){


    cam >> frames_1;
    cv::resize(frames_1, frames_1, cv::Size(), 1, 1);
    cv::cvtColor(frames_1, grayIm_1, CV_RGB2GRAY);

    test_1->detect(grayIm_1, keypoints_1);

    for (int i = 0; i<keypoints_1.size(); i++)
        cv::circle(img_1, cv::Point(keypoints_1[i].pt.x, keypoints_1[i].pt.y), 5, cv::Scalar(255, 0, 0, 255));

    if (count == 0){
        int currenttick = cv::getTickCount();
        FPS = cv::getTickFrequency() / (currenttick - prevTick) * 30;
        if (FPS_count != 0) FPS_sum += FPS;
        FPS_count++;
        prevTick = cv::getTickCount();
    }
    count = ++count % 30;

    cam >> frames;
    cv::resize(frames, frames, cv::Size(), 1, 1);
    cv::cvtColor(frames, grayIm, CV_RGB2GRAY);

    test->detect(grayIm, keyp);

    for (int i = 0; i<keyp.size(); i++)
        cv::circle(frames, cv::Point(keyp[i].pt.x, keyp[i].pt.y), 5, cv::Scalar(255, 0, 0, 255));

    if (count == 0){
        int currenttick = cv::getTickCount();
        FPS = cv::getTickFrequency() / (currenttick - prevTick) * 30;
        if (FPS_count != 0) FPS_sum += FPS;
        FPS_count++;
        prevTick = cv::getTickCount();
    }
    count = ++count % 30;

    sprintf(str, "FPS = %0.2f\0", FPS);
    cv::putText(frames, str, cv::Point(20, 50), CV_FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(255, 0, 255, 0));

    cv::imshow("Camera", frames);
    cout << "Average FPS = " << FPS_sum / (FPS_count - 1) << std::endl;




    //-- Step 2: Calculate descriptors (feature vectors)
    SurfDescriptorExtractor extractor;

    Mat descriptors_1, descriptors_2;

    extractor.compute(img_1, keypoints_1, descriptors_1);
    extractor.compute(frames, keyp, descriptors_2);

    //-- Step 3: Matching descriptor vectors with a brute force matcher

    FlannBasedMatcher matcher;

    std::vector< DMatch > matches;
    matcher.match(descriptors_1, descriptors_2, matches);

    //-- Draw matches
    Mat img_matches;
    drawMatches(img_1, keypoints_1, frames, keyp, matches, img_matches);

    cv::cvtColor(img_matches, img_matches, CV_RGB2GRAY);
    //-- Show detected matches
    imshow("Matches", img_matches);

}

}

/** @function readme */ void readme() { std::cout << " Usage: ./SURF_descriptor <img1> <img2>" << std::endl; }

///////////////////////////////////////////////WARNINGS////////////////////////////////////// look ad the picture.!!!!WARNINGS... warning C4244: 'argument' : conversion from 'float' to 'int', possible loss of data......

![While its working(/upfiles/14277979179149247.jpg)

and when its down....

Video capture and search for a image in a database.....WARNING

We would like to capture a video over the webcam (in real time) and then search for QR code and compare the code that we have found with a database of QR codes.

include "opencv2/calib3d/calib3d.hpp"

include "opencv2/nonfree/nonfree.hpp"

include "opencv2/core/core.hpp"

include "opencv2/features2d/features2d.hpp"

include <opencv2 highgui="" highgui.hpp="">

include <opencv2 imgproc="" imgproc.hpp="">

include <windows.h>

include <iostream>

include <stdio.h>

include <legacy\legacy.hpp>

include <cxcore.h>

#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/nonfree/nonfree.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <Windows.h>
#include <iostream>
#include <stdio.h>
#include <legacy\legacy.hpp>
#include <cxcore.h>


using namespace cv;
using namespace std;

std; void readme();

/* readme(); /** @function main */ int main(int argc, char char* argv[]) {

{


    VideoCapture cam(1);

 cam.set(CV_CAP_PROP_FRAME_HEIGHT, 240);
 cam.set(CV_CAP_PROP_FRAME_WIDTH, 320);

 cv::Mat frames, frames_1;
 cv::Mat grayIm, grayIm_1;
 double FPS = 0.;
 double FPS_sum = 0.;
 int FPS_count = 0;
 long prevTick = 0;
 int count = 0;
 char str[256] = { '\0' };


 Mat img_1 = imread("C:\\Users\\Sony\\Desktop\\slika_1.jpg", CV_LOAD_IMAGE_GRAYSCALE);



 std::vector<KeyPoint> keypoints_1;

 ////

 cam >> frames_1;
 grayIm.create(frames_1.rows, frames_1.cols, frames_1.type());

 cv::Ptr<cv::FeatureDetector> test_1 = cv::FeatureDetector::create("FAST");

 ////



 std::vector<cv::KeyPoint> keyp;

 if (!cam.isOpened())
     return -1;

 cam >> frames;
 grayIm.create(frames.rows, frames.cols, frames.type());

 cv::Ptr<cv::FeatureDetector> test = cv::FeatureDetector::create("FAST");


 while (cv::waitKey(1) != 27){


     cam >> frames_1;
     cv::resize(frames_1, frames_1, cv::Size(), 1, 1);
     cv::cvtColor(frames_1, grayIm_1, CV_RGB2GRAY);

     test_1->detect(grayIm_1, keypoints_1);

     for (int i = 0; i<keypoints_1.size(); i++)
         cv::circle(img_1, cv::Point(keypoints_1[i].pt.x, keypoints_1[i].pt.y), 5, cv::Scalar(255, 0, 0, 255));

     if (count == 0){
         int currenttick = cv::getTickCount();
         FPS = cv::getTickFrequency() / (currenttick - prevTick) * 30;
         if (FPS_count != 0) FPS_sum += FPS;
         FPS_count++;
         prevTick = cv::getTickCount();
     }
     count = ++count % 30;

     cam >> frames;
     cv::resize(frames, frames, cv::Size(), 1, 1);
     cv::cvtColor(frames, grayIm, CV_RGB2GRAY);

     test->detect(grayIm, keyp);

     for (int i = 0; i<keyp.size(); i++)
         cv::circle(frames, cv::Point(keyp[i].pt.x, keyp[i].pt.y), 5, cv::Scalar(255, 0, 0, 255));

     if (count == 0){
         int currenttick = cv::getTickCount();
         FPS = cv::getTickFrequency() / (currenttick - prevTick) * 30;
         if (FPS_count != 0) FPS_sum += FPS;
         FPS_count++;
         prevTick = cv::getTickCount();
     }
     count = ++count % 30;

     sprintf(str, "FPS = %0.2f\0", FPS);
     cv::putText(frames, str, cv::Point(20, 50), CV_FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(255, 0, 255, 0));

     cv::imshow("Camera", frames);
     cout << "Average FPS = " << FPS_sum / (FPS_count - 1) << std::endl;




     //-- Step 2: Calculate descriptors (feature vectors)
     SurfDescriptorExtractor extractor;

     Mat descriptors_1, descriptors_2;

     extractor.compute(img_1, keypoints_1, descriptors_1);
     extractor.compute(frames, keyp, descriptors_2);

     //-- Step 3: Matching descriptor vectors with a brute force matcher

     FlannBasedMatcher matcher;

     std::vector< DMatch > matches;
     matcher.match(descriptors_1, descriptors_2, matches);

     //-- Draw matches
     Mat img_matches;
     drawMatches(img_1, keypoints_1, frames, keyp, matches, img_matches);

     cv::cvtColor(img_matches, img_matches, CV_RGB2GRAY);
     //-- Show detected matches
     imshow("Matches", img_matches);

 }

}

} /** @function readme */ void readme() { std::cout << " Usage: ./SURF_descriptor <img1> <img2>" << std::endl; }

}

///////////////////////////////////////////////WARNINGS////////////////////////////////////// look ad the picture.!!!!WARNINGS... warning C4244: 'argument' : conversion from 'float' to 'int', possible loss of data......

![While its working(/upfiles/14277979179149247.jpg)

and when its down....