kylemcdonald / ofxCv

Alternative approach to interfacing with OpenCv from openFrameworks.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rotate matrix

HalfdanJ opened this issue · comments

For another project i needed a fast rotating of images, but only in increments of 90 (for rotating camera image).

Following code is what i found:

void rotate_90n(cv::Mat &src, cv::Mat &dst, int angle)
{
    if(angle == 270 || angle == -90){
        // Rotate clockwise 270 degrees
        cv::flip(src.t(), dst, 0);
    }else if(angle == 180 || angle == -180){
        // Rotate clockwise 180 degrees
        cv::flip(src, dst, -1);
    }else if(angle == 90 || angle == -270){
        // Rotate clockwise 90 degrees
        cv::flip(src.t(), dst, 1);
    }else if(angle == 360 || angle == 0){
        if(src.data != dst.data){
            src.copyTo(dst);
        }
    }
}

Worth adding to ofxCv?

sure, do you want to modify ofxCv::rotate90() to add the extra cases (for the negative values) and do the transpose inline?