Blurred QRcode detection from video stream with OpenCV

asked 2018-07-04 14:56:03 -0600

iacopo gravatar image

updated 2018-07-04 15:24:11 -0600

I'm trying to extrapolate from a video stream, some QR codes that have been modified to not be easily recognizable. I've to use OpenCV. The problem is that the code is able to recognize only the qr codes well visible, while the qr codes that it must recognize are blurred. I believe that the problem is some parameters, but i can't find it. According to you where is the problem?

this is the code i use:

#include <opencv2/opencv.hpp>
#include <iostream>
#include <cmath>

using namespace cv;
using namespace std;

const int CV_QR_NORTH = 0;
const int CV_QR_EAST = 1;
const int CV_QR_SOUTH = 2;
const int CV_QR_WEST = 3;

int counter = 0;



float cv_distance(Point2f P, Point2f Q);                    // Get Distance between two points
float cv_lineEquation(Point2f L, Point2f M, Point2f J);     // Perpendicular Distance of a Point J from line formed by Points L and M; Solution to equation of the line Val = ax+by+c 
float cv_lineSlope(Point2f L, Point2f M, int& alignement);  // Slope of a line by two Points L and M on it; Slope of line, S = (x1 -x2) / (y1- y2)
void cv_getVertices(vector<vector<Point> > contours, int c_id, float slope, vector<Point2f>& X);
void cv_updateCorner(Point2f P, Point2f ref, float& baseline, Point2f& corner);
void cv_updateCornerOr(int orientation, vector<Point2f> IN, vector<Point2f> &OUT);
bool getIntersectionPoint(Point2f a1, Point2f a2, Point2f b1, Point2f b2, Point2f& intersection);
float cross(Point2f v1, Point2f v2);

// Start of Main Loop
//------------------------------------------------------------------------------------------------------------------------
int main(int argc, char **argv)
{
    VideoCapture capture;
    capture.open("video.mp4");

//Mat image = imread(argv[1]);
Mat image;

if (!capture.isOpened()) {
    cerr << " ERR: Unable find input Video source." << endl;
    return -1;
}

//Step  : Capture a frame from Image Input for creating and initializing manipulation variables
//Info  : Inbuilt functions from OpenCV
//Note  : 

capture >> image;
if (image.empty()) {
    cerr << "ERR: Unable to query image from capture device.\n" << endl;
    return -1;
}


// Creation of Intermediate 'Image' Objects required later
Mat gray(image.size(), CV_MAKETYPE(image.depth(), 1));          // To hold Grayscale Image
Mat edges(image.size(), CV_MAKETYPE(image.depth(), 1));         // To hold Grayscale Image
Mat traces(image.size(), CV_8UC3);                              // For Debug Visuals
Mat qr, qr_raw, qr_gray, qr_thres;


vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
vector<Point> pointsseq;    //used to save the approximated sides of each contour

int mark, A, B, C, top, right, bottom, median1, median2, outlier;
float AB, BC, CA, dist, slope, areat, arear, areab, large, padding;

int align, orientation;

int DBG = 1;                        // Debug Flag

int key = 0;
while (key != 'q')              // While loop to query for Image Input frame
{

    traces = Scalar(0, 0, 0);

    qr_raw = Mat::zeros(100, 100, CV_8UC3); 
    qr = Mat::zeros(100, 100, CV_8UC3);
    qr_gray = Mat::zeros(100, 100, CV_8UC1);
    qr_thres = Mat::zeros(100, 100, CV_8UC1);

    capture >> image;                       // Capture Image from Image Input

    cvtColor(image, gray, CV_RGB2GRAY);     // Convert Image captured from Image Input to GrayScale 
    Canny(gray, edges, 100, 200, 3);        // Apply Canny edge detection on the gray image


    findContours(edges, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE); 

    mark = 0;                               // Reset all detected marker count for this frame

                                            // Get Moments for all Contours and the mass centers ...
(more)
edit retag flag offensive close merge delete

Comments

Why don't you post full question here with images in post ( and add a ref to satckoverflow post)?

LBerger gravatar imageLBerger ( 2018-07-04 15:17:11 -0600 )edit
1

Now I have modified the question @LBerger.

iacopo gravatar imageiacopo ( 2018-07-04 15:25:35 -0600 )edit

could you add 1 or 2 images here, so folks don't have to access a 3rd party dropbox ?

also just saying, - do you expect us to debug 600+ lines of code for you ? it probably won't happen.

berak gravatar imageberak ( 2018-07-06 05:06:46 -0600 )edit