#ifndef LIBQR_H
#define LIBQR_H
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/core.hpp"
#include "opencv2/calib3d.hpp"
#include <string>
#include <vector>

using namespace cv;
using namespace std;
typedef Mat CvImg;

struct ProcessState {
    CvImg *orig;
    std::vector<Point> qr_points;
    float scale;
    Mat transform;
    CvImg preprocessed;
    CvImg straighten;
    Rect qr_rect_in_straighten;
    CvImg qr_straighten;
    CvImg left_mid_area;
    string qrcode = "";
    float sobel_thres = 15;
    int sharpness_method = 2;
    float clarity = 0;
};

bool preprocess(ProcessState &ps);
bool emblem_dot_angle(ProcessState &ps, cv::InputArray in, float &angle, std::string &qrcode, std::string &err);
bool detect_qr(ProcessState &ps, float margin_ratio, bool warp, string &err);
enum SimilarityAlg {
    CellWeight,
    FuzzyPixelCmp,
};
double emblem_roi_similarity(SimilarityAlg alg, InputArray a, InputArray b, string &err);

static inline void showimg_(const char *title, Mat &img) {
    imshow(title, img);
    waitKey(0);
}

#define show(img) showimg_(#img, img)


#endif
