如何将使用 OpenCV c++ 的图像偏斜检测和校正代码转换为 OpenCV python。我尝试转换以下代码,但它不起作用。
Mat src=imread("text.png",0);
Mat thr,dst;
threshold(src,thr,200,255,THRESH_BINARY_INV);
imshow("thr",thr);
std::vector<cv::Point> points;
cv::Mat_<uchar>::iterator it = thr.begin<uchar>();
cv::Mat_<uchar>::iterator end = thr.end<uchar>();
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, box.angle, 1);
//cv::Mat rotated(src.size(),src.type(),Scalar(255,255,255));
Mat rotated;
cv::warpAffine(src, rotated, rot_mat, src.size(), cv::INTER_CUBIC);
imshow("rotated",rotated);
最佳答案
*它总是正确的。我觉得你应该试试
if (!thr.at<uchar>(it.pos()))
也许是你的错
关于python - opencv python中图像倾斜检测的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31190065/