【问题标题】:code for skew detection of image in opencv python在opencv python中对图像进行倾斜检测的代码
【发布时间】:2015-07-02 16:34:15
【问题描述】:

如何使用 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);

【问题讨论】:

    标签: python c++ opencv image-processing skew


    【解决方案1】:

    *它总是正确的。我觉得你应该试试

    if (!thr.at<uchar>(it.pos()))
    

    也许是你的错

    【讨论】:

    • 在阈值之后*它评估为 0 或 255 并正确转换为 bool
    猜你喜欢
    • 1970-01-01
    • 2012-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多