How to reduce motion blur in picture?

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

please show your data.

such a thing as “unblur” exists (deconvolution) but it’s an expensive and complicated operation and you should not even consider looking into that because it’s way too complicated to make work here.

also, stay away from Canny. using Canny frequently destroys all the information in the picture. it’s an algorithm with very specific uses, and to be left to experts.

you should instead make sure to get data that isn’t blurry.

Thanks for your reply. Data is attached along with original post.
I see your point to about not getting the blurry data. Answer to this question is very expensive. :slight_smile: We might need camera which is more frames per second. Currently I am using 30 frames per second, which is standard.

Thanks for mentioning about canny as well. It is commented out in my code. :slight_smile:

if the issue is motion blur, just add more light.

frames per second are meaningless when the issue is any kind of blur. exposure time is relevant for motion blur.

Yes, the issue is motion blur. I am doing these experiments during my day time and light should not be a problem there, I believe. However, I would take your suggestion and try to improve the lighting. Is there anything technically I can improve in my code?

Also, I see your point about frames per second as well. I was under the impression that if I have a camera which is higher fps, then there is less possibility that the blur might occur in the image. Seems like you would not agree with that. :slight_smile:


daytime maybe, but the picture on SO certainly doesn’t look remotely like direct sunlight

really, this requires more light. and if the camera has any kind of aperture control, set it to wide open (and make sure the object is in focus). wide open so the camera uses exposure time to control total exposure.