Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to remove cv::RotatedRect after use in opencv..?
    primarykey
    data
    text
    <p>What I am doing is => I'm capturing the image, after that I'm calculating the skew angle of captured image and then I'm rotating that image according to calculated skew angle. Everything is working fine, but the problem is I have used <strong><em>cv::RotatedRect</em></strong> in my code and because of this my resulting image contains that box also, I wants to remove that box from my resulting image, Anybody has any Idea How can I remove that box..? I'm specifying my code below.. Please help..! Thanks..! [I cant upload my resulting image, because I am new to StackOverflow and yet I don't have rights to upload the image.]</p> <pre><code>// Function to Find Skew angle. double compute_skew(const char* filename) { // Load in grayscale. cv::Mat img = cv::imread(filename, 0); // Binarize cv::threshold(img, img, 225, 255, cv::THRESH_BINARY); // Invert colors cv::bitwise_not(img, img); cv::Mat element = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(5, 3)); cv::erode(img, img, element); std::vector&lt;cv::Point&gt; points; cv::Mat_&lt;uchar&gt;::iterator it = img.begin&lt;uchar&gt;(); cv::Mat_&lt;uchar&gt;::iterator end = img.end&lt;uchar&gt;(); for (; it != end; ++it) if (*it) points.push_back(it.pos()); cv::RotatedRect box = cv::minAreaRect(cv::Mat(points)); double angle = box.angle; if (angle &lt; -45.) angle += 90.; cv::Point2f vertices[4]; box.points(vertices); for(int i = 0; i &lt; 4; ++i) cv::line(img, vertices[i], vertices[(i + 1) % 4], cv::Scalar(255, 0, 0), 1, CV_AA); std::cout &lt;&lt; "File **************Angle***************** " &lt;&lt; filename &lt;&lt; ": " &lt;&lt; angle &lt;&lt; std::endl; return angle; </code></pre> <p>}</p> <pre><code>// Function to rotate image image void deskew(const char* filename, double angle) { //angle = 90; cv::Mat img = cv::imread(filename, 0); cv::bitwise_not(img, img); std::vector&lt;cv::Point&gt; points; cv::Mat_&lt;uchar&gt;::iterator it = img.begin&lt;uchar&gt;(); cv::Mat_&lt;uchar&gt;::iterator end = img.end&lt;uchar&gt;(); for (; it != end; ++it) if (*it) points.push_back(it.pos()); cv::RotatedRect box = cv::minAreaRect(cv::Mat(points)); cv::Mat rot_mat = cv::getRotationMatrix2D(box.center, angle, 1); cv::Mat rotated; cv::warpAffine(img, rotated, rot_mat, img.size(), cv::INTER_CUBIC); cv::bitwise_not(rotated, rotated); imwrite(filename,rotated); </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload