python - opencv python中图像倾斜检测的代码

标签 python c++ opencv image-processing skew

如何将使用 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/

相关文章:

python - 列表理解表达式不显示任何值而不是子列表

python - ZeroMQ 没有收到客户端程序发送的值

python - RopeVim 中的代码辅助......你如何使用它?

python - 为什么 SMOTE 不能处理超过 15 个特征/什么方法可以处理超过 15 个特征?

java - 多线程 JNI 调用

c++ - C++ 标准是否保证 std::basic_string::npos + 1 == 0?

c++ - 包装 STL 以扩展

c++ - 如何为多车道检测过滤霍夫线?

c++ - OpenCV 中的局部归一化

python - labelEncoder在sklearn中的工作