Does Qt allow to translate (or crop) images with sub-pixel accuracy?
The use case is a 2D map with a vehicle at the origin. The map shall also be translated in case the vehicle moves e.g. 0.5 pixels. I believe this should be feasible in principle using bilinear interpolation or similar.
Minimal example:
#include <QtWidgets/QApplication>
#include <QtGui/QImage>
#include <QLabel>
int main(int argc, char *argv[])
{
// Parameters
QString PATH_IMG_IN
= "../img_test_rect.jpg";
QString PATH_IMG_OUT
= "../img_out.png";
float TRANSLATE_IN_PX = 0.5;
// load image
img.load(PATH_IMG_IN);
// rotate image.
QTransform trans;
trans.translate(0,TRANSLATE_IN_PX);
QImage img_new
= img.
transformed(trans, Qt
::SmoothTransformation);
// save image
img_new.save(PATH_IMG_OUT, nullptr, 100);
// optional: Get info about true transformation matrix
QTransform trans_true
= QImage::trueMatrix(trans, img.
width(), img.
height());
return app.exec();
}
#include <QtWidgets/QApplication>
#include <QtGui/QImage>
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
// Parameters
QString PATH_IMG_IN = "../img_test_rect.jpg";
QString PATH_IMG_OUT = "../img_out.png";
float TRANSLATE_IN_PX = 0.5;
// load image
QImage img;
img.load(PATH_IMG_IN);
// rotate image.
QTransform trans;
trans.translate(0,TRANSLATE_IN_PX);
QImage img_new = img.transformed(trans, Qt::SmoothTransformation);
// save image
img_new.save(PATH_IMG_OUT, nullptr, 100);
// optional: Get info about true transformation matrix
QTransform trans_true = QImage::trueMatrix(trans, img.width(), img.height());
return app.exec();
}
To copy to clipboard, switch view to plain text mode
I also tried using "void QPainter::drawImage(const QPointF &point, const QImage &image)" without success. Moreover, I found a few threads without answer such as https://stackoverflow.com/questions/...48425_40552885
It seems to me that Qt does not enable this feature at the moment, but I am just guessing, not knowing.
Bookmarks