am trying to detect the QR data from an blurred image and have not been successfull till now. I have tried couple of morphology operations on the image and still did not get the data embedded in it.
Idea is to unblur the image first and then get the data. Would like to know this from you gentleman that what is the standard for doing that?
I have tried this so far:
#include <iostream>
#include <opencv2/highgui.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/objdetect.hpp>
#include <opencv2/barcode.hpp>
int main() {
cv::Mat imageMat = cv::imread("/Users/apple/Downloads/36.jpg");
if(imageMat.empty()) {
std::cout << "Image not present and can not be opened" << std::endl;
return 0;
}
cv::Mat imageGray, imageBlur, imageCanny, imageDilated, imageEroded, thresholdImage;
cv::cvtColor(imageMat, imageGray, cv::COLOR_BGR2GRAY);
cv::GaussianBlur(imageGray, imageBlur, cv::Size(3,3), 3, 0);
std::cout << "Gaussian blur done" << std::endl;
// cv::Canny(imageBlur, imageCanny, 25, 75);
cv::Mat kernel = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(3,3));
cv::dilate(imageBlur, imageDilated, kernel);
cv::erode(imageDilated, imageEroded, kernel);
cv::threshold(imageEroded, thresholdImage, 5, 255, cv::THRESH_BINARY+cv::THRESH_OTSU);
std::cout << "Threshold done" << std::endl;
// Reads the barcode/dat
cv::QRCodeDetector qrDecoder;
std::string decodedData = qrDecoder.detectAndDecode(thresholdImage);
std::cout << "Decoded data = " << decodedData << std::endl;
This code is not working. What would you guys prefer to unblur the image and get the data embedded. Increase the contrast? Increase the brightness? Any document/pointers can be helpful too.
Thank you in advance.