Note that there are some explanatory texts on larger screens.

plurals
  1. POFind Skew Angle and Rotate the Image in C++ OpenCV
    primarykey
    data
    text
    <p>Need help, Plz see the following question, I'm asking this question second time, because last time I didn't get any answer. Consider following Two links => <a href="http://felix.abecassis.me/2011/09/opencv-detect-skew-angle/" rel="nofollow">1:=> Finding Skew Angle</a> <a href="http://felix.abecassis.me/2011/10/opencv-rotation-deskewing/" rel="nofollow">2:=> Rotating Image as per skew angle</a></p> <p>I wants to do the same, and the code given on this links works good. But the problem is, See the text displayed in these images, this code works fine for well aligned text only (as displayed in the images on the given links), but It gets failed when your text is in scattered form. Please tell me how to do it for images that contains text in the scattered form..? Thanks in advance..!! [ Here the main challenge is TO FIND CORRECT SKEW ANGLE..] I am very frustrated because of this problem... Plz Help..!!!</p> <p>My Code is as follows:=></p> <pre><code>// 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; } // Rotate Image according to skew angle. void deskew(const char* filename, double angle) { cv::Mat img = cv::imread(filename, 0); Point2f src_center(img.cols/2.0F, img.rows/2.0F); Mat rot_mat = getRotationMatrix2D(src_center, angle, 1.0); Mat rotated; warpAffine(img, rotated, rot_mat, img.size(), cv::INTER_CUBIC); imwrite(filename,rotated); } </code></pre>
    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