alg: Add check_blur_by_sobel
This commit is contained in:
parent
6d4f831003
commit
35dfd23069
@ -240,13 +240,38 @@ bool check_blur_by_laplacian(ProcessState &ps, Mat &gray, string &err)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
bool check_blur(ProcessState &ps, Mat &gray, string &err)
|
bool check_blur_by_sobel(ProcessState &ps, Mat &gray, string &err)
|
||||||
{
|
{
|
||||||
bool use_energy_gradient = false;
|
const float thres = 15;
|
||||||
if (use_energy_gradient) {
|
Mat sobel_x, sobel_y;
|
||||||
return check_blur_by_energy_gradient(gray, err);
|
Sobel(gray, sobel_x, CV_64F, 1, 0, 3);
|
||||||
|
Sobel(gray, sobel_y, CV_64F, 0, 1, 3);
|
||||||
|
|
||||||
|
Mat magnitude;
|
||||||
|
magnitude = sobel_x.mul(sobel_x) + sobel_y.mul(sobel_y); // Gx^2 + Gy^2
|
||||||
|
sqrt(magnitude, magnitude); // sqrt(Gx^2 + Gy^2)
|
||||||
|
|
||||||
|
Scalar meanMagnitude = mean(magnitude);
|
||||||
|
double sharpness = meanMagnitude[0] / (gray.rows * gray.cols) * 1000;
|
||||||
|
if (sharpness < thres) {
|
||||||
|
err = string_format("image too blurry: %lf < %lf", sharpness, thres);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return check_blur_by_laplacian(ps, gray, err);
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
bool check_sharpness(ProcessState &ps, Mat &gray, int method, string &err)
|
||||||
|
{
|
||||||
|
if (method == 0) {
|
||||||
|
return check_blur_by_laplacian(ps, gray, err);
|
||||||
|
} else if (method == 1) {
|
||||||
|
return check_blur_by_energy_gradient(gray, err);
|
||||||
|
} else if (method == 2) {
|
||||||
|
return check_blur_by_sobel(ps, gray, err);
|
||||||
|
}
|
||||||
|
err = "unknown sharpness method: " + to_string(method);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define COUNT_COMPONENTS 0
|
#define COUNT_COMPONENTS 0
|
||||||
@ -429,7 +454,7 @@ bool emblem_dot_angle(ProcessState &ps, InputArray in, float &angle, string &qrc
|
|||||||
|
|
||||||
qrcode = ps.qrcode;
|
qrcode = ps.qrcode;
|
||||||
|
|
||||||
if (!check_blur(ps, ps.dot_area_gray, err)) {
|
if (!check_sharpness(ps, ps.dot_area_gray, ps.sharpness_method, err)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -25,6 +25,7 @@ struct ProcessState {
|
|||||||
string qrcode = "";
|
string qrcode = "";
|
||||||
double clarity;
|
double clarity;
|
||||||
float laplacian_thres = 0.1;
|
float laplacian_thres = 0.1;
|
||||||
|
int sharpness_method = 2;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool preprocess(ProcessState &ps);
|
bool preprocess(ProcessState &ps);
|
||||||
|
|||||||
@ -23,10 +23,12 @@ std::string make_resp(bool ok, string err, int angle = -1, string qrcode = "", d
|
|||||||
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
const char *qrtool_angle(uint8_t *data, int width, int height, uint8_t *dot_area, float camera_sensitivity) {
|
const char *qrtool_angle(uint8_t *data,
|
||||||
|
int width, int height,
|
||||||
|
uint8_t *dot_area,
|
||||||
|
float camera_sensitivity) {
|
||||||
ProcessState ps;
|
ProcessState ps;
|
||||||
ps.laplacian_thres = camera_sensitivity / 10.0;
|
ps.laplacian_thres = camera_sensitivity / 10.0;
|
||||||
|
|
||||||
auto start = std::chrono::system_clock::now();
|
auto start = std::chrono::system_clock::now();
|
||||||
static char ret[512];
|
static char ret[512];
|
||||||
printf("qrtool_angle, width: %d height %d\n", width, height);
|
printf("qrtool_angle, width: %d height %d\n", width, height);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user