Vision Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
andreasbj

Fast way of rotating an image 90 degrees in IMAQ

Status: New

Problem:

I need to acquire images from a camera and rotate them 90-degrees counter-clockwise on a cRIO-9034 target. Rotating the image on the camera sensor is not supported by the camera.

 

Current situation:

IMAQ rotate.png

It is currently possible to rotate an image using “IMAQ Rotate.vi”. This VI has a floating point input angle which can be set to 90 degrees. It is however a bit slow (around 80 ms on a cRIO-9034 for a 3840x1200 image). It should be possible to implement a faster way of rotating an image when the angle is in increments of 90 degrees.

 

My suggestion:

Create a new IMAQ vi for rotating images in increments of 90 degrees. The VI could be similar to "IMAQ Symmetry.vi" which can be used to flip images horizontally and vertically.

 

Best regards,
Andreas
3 Comments
ng1902
Member

A faster rotate would be great. Rotations were taking too long on an application we were developing so we created two simple OpenCV calls (using the OpenCV Utilities package as an example), one which rotates an image by any angle and one which rotates by increments of 90 degrees.

 

On my laptop with a 4112x2176 image, the built-in LabVIEW rotate takes an average of 135ms, while the OpenCV call averages 20ms.

 

When rotating by increments of 90 degrees, the built-in LabVIEW rotate averages 45ms, while OpenCV averages 10ms.

 

I would love it if the performance of image rotation could be improved, and there clearly is room for improvement. 

mattvx
Member

Ng1902, would you mind sharing that code or the function you used? Thanks.

This is the example ive seen. Maybe it's possible to implement with call library function node.

void rotate(InputArray src, OutputArray dst, int rotateCode);

with

enum RotateFlags {
    ROTATE_90_CLOCKWISE = 0, //Rotate 90 degrees clockwise
    ROTATE_180 = 1, //Rotate 180 degrees clockwise
    ROTATE_90_COUNTERCLOCKWISE = 2, //Rotate 270 degrees clockwise
};

 

ng1902
Member

The function you posted works great for 90° rotations. For other angles, this is what we use:

 

Rotate.cpp

#include "Rotate.h"

void rotate(cv::Mat& src, double angle, cv::Mat& dst, bool use_interpolation) {
	cv::Point2f ptCp(src.cols*0.5, src.rows*0.5);
	cv::Mat M = cv::getRotationMatrix2D(ptCp, angle, 1.0);
	auto interp = use_interpolation ? cv::INTER_LINEAR : cv::INTER_NEAREST;
	cv::warpAffine(src, dst, M, src.size(), interp); 
}

 

 

Rotate.h

#pragma once
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>

extern "C" void __declspec(dllexport) rotate(cv::Mat& src, 
											 double angle, 
											 cv::Mat& dst,
											 bool use_interpolation);

 

We installed the NIVison OpenCV Utilities package from VIPM and used that as the starting point. This package comes with some source code & examples which helped us call it through the Call Library Function node.