Dynamic Image Perspective and Cropping

I'm new to C++ but have some experience with octave/matlab. I am trying to make a program that is able to take an image of a package with a barcode label visible, crop the image to the label's shape while adjusting the perspective so as to produce an image of the label that is aligned straight. I need to do this to perform some image analysis for the healing process I have planned.

I messed around with hough transforms in octave, but without success. I moved to C++ because I have heard it's the industry standard, and I'd like to be able to package the program.

Have any of you had experience with image manipulation along these lines?
If you're just moving from matlab to C++ and want to be able to do a bunch of image processing, it's going to be a challenge to learn the differences and set things up. C++ doesn't come with anything specifically built-in to handle image processing. You'll either need to make your own (not suggested), or learn existing libraries.

Matlab already has pretty nice built-ins for cropping, rotating, and matrix objects for applying transformations for adjusting perspective. Making a prototype in Matlab sounds like it would be much easier. I have not done this myself, but matlab functions apparently can be compiled for deployment:
https://www.mathworks.com/help/mps/ml_code/mcc.html

But if you still want to do this in C++ instead:

The hardest part of your problem isn't the cropping, rotating, or perspective transformations themselves -- rather, it's the image recognition to find where the barcode is on an image, and then determine its perspective. I assume you want the program to be able to do this automatically given a raw image.

For general advanced object recognition, people usually go to OpenCV. But a google search I did found me this library:
https://github.com/zxing/zxing
https://en.wikipedia.org/wiki/Barcode_Scanner_(application)
It's in Java, but the algorithms and basic logic can be translated into C++, or Matlab if you take the time. It supports recognition of multiple types of barcodes. You could try exploring the code and seeing what you could learn from it.

https://en.wikipedia.org/wiki/Transformation_matrix#Perspective_projection

To get started in C++, some basic image-reading libraries that come to mind are libjpeg and libpng. And libraries like GLM (OpenGL Mathematics) provide matrix structures. There might be C++ translations of Matlab built-ins you could find, I don't know. Cropping can be done without a library once you have the pixel data itself, but I'm sure one already exists if you don't want to re-invent the wheel.
Last edited on
Thank you very much for the detailed reply. I definitely will think things over a little bit before deciding on matlab vs C++. Ultimately I'd like to be proficient in C++ but for now if I can get it working in matlab more easily I'll probably take that route.
Topic archived. No new replies allowed.