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

asked 2015-03-31 05:43:18 -0500

Petre gravatar image

updated 2015-03-31 06:34:48 -0500

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....

edit retag flag offensive close merge delete

Comments

And the question is?

FooBar gravatar imageFooBar ( 2015-03-31 06:37:23 -0500 )edit

The question si how to get rid of warnings.... And how to solve application crashes

tadej_r gravatar imagetadej_r ( 2015-03-31 07:46:21 -0500 )edit

Warnings: don't assign a float value to an integer parameter. Crash: in which line does the application crash?

FooBar gravatar imageFooBar ( 2015-03-31 09:12:52 -0500 )edit

Yes we know that but we don't know how to solve that its possible that the error occurs because the video descriptor mat and train descriptor mat doesn't have the same type?? (And how to change this)......crash report:: opencv assertion failed <query descriptors.type()="Train" des="" collection="" [0]="" in="" cv::bfmatcher::knnmatchimpl="" file="" c:\builds\2_4_packslave-win64-vc12-shared\opencv\features2d\src\matchers.cpp.="" line="" 351<="" p="">

Petre gravatar imagePetre ( 2015-03-31 09:54:00 -0500 )edit

warning C4244: 'argument' : conversion from 'float' to 'int', possible loss of data line 77 warning C4244: 'initializing' : conversion from 'int64' to 'int', possible loss of data line 80 warning C4244: '=' : conversion from 'int64' to 'long', possible loss of data line 84

warning C4244: 'argument' : conversion from 'float' to 'int', possible loss of data line 95 warning C4244: 'initializing' : conversion from 'int64' to 'int', possible loss of data line 98 warning C4244: '=' : conversion from 'int64' to 'long', possible loss of data line 102

Petre gravatar imagePetre ( 2015-03-31 10:08:59 -0500 )edit