Ask Your Question
0

How to rotate putText from the Android studio.

asked 2020-07-11 01:49:35 -0500

ki gravatar image

I accidentally set the screen horizontally. So the letters look horizontal. I want to know how to rotate the letters From the Android studio.

putText(matInput, "R:2", Point(150, 320), 1, 8, Scalar::all(255),6);

It is my putText coding.

image description

The screen is running.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2020-07-11 02:20:26 -0500

berak gravatar image

updated 2020-07-11 02:21:43 -0500

there's no easy way provided for this,

you will have to rotate() your image, draw the text with swapped x,y coords, and rotate it back

I accidentally set the screen horizontally.

it might be easier to fix that instead

edit flag offensive delete link more
-1

answered 2020-07-12 04:05:18 -0500

supra56 gravatar image

Try this:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>

using namespace std;
using namespace cv;

void rotate(cv::Mat& src, double angle, cv::Mat& dst)
{
    int len = std::max(src.cols, src.rows);
    cv::Point2f pt(len/2., len/2.);
    cv::Mat r = cv::getRotationMatrix2D(pt, angle, 1.0);

    cv::warpAffine(src, dst, r, cv::Size(len, len));
}


int main() {

    Mat img = imread("OpenCV_Logo.jpg", CV_LOAD_IMAGE_COLOR);

    Mat textImg = Mat::zeros(img.rows, img.cols, img.type());
    putText(textImg, "R:2", Point(0, img.cols/2), FONT_HERSHEY_SIMPLEX, 2.0,Scalar(288,0,0),2);
    rotate(textImg, -90, textImg);

    img= img+textImg;

    namedWindow("Rotate Text", CV_WINDOW_AUTOSIZE);
    imshow("Rotate Text", img);

    waitKey(0);
    return 0;
}
edit flag offensive delete link more

Comments

I don't know if if workehd on Android.

supra56 gravatar imagesupra56 ( 2020-07-12 04:24:54 -0500 )edit

it is a java problem, unfortunately, not c++

also, your rotated textImg must have the same size as the original

berak gravatar imageberak ( 2020-07-12 08:25:30 -0500 )edit

I apply to Android But the coding you wrote seems to be optimized for the computer. It doesn't work.

ki gravatar imageki ( 2020-07-12 14:31:38 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2020-07-11 01:49:35 -0500

Seen: 61 times

Last updated: Jul 12