• 单字符旋转校正


     
    通过求外接椭圆,算出纠正角度

    // ration2.cpp : 定义控制台应用程序的入口点。
    //
    #include "stdafx.h"
    #include "highgui.h"
    #include "cv.h"
    #include "cxcore.h"
    #ifdef DEBUG
    #pragma comment(lib," opencv_core231d.lib")
    #pragma comment(lib,"opencv_features2d231d.lib")
    #pragma comment(lib,"opencv_flann231d.lib")
    #pragma comment(lib,"opencv_gpu231d.lib")
    #pragma comment(lib,"opencv_highgui231d.lib")
    #pragma comment(lib,"opencv_imgproc231d.lib")
    #else
    #pragma comment(lib,"opencv_core231.lib")
    #pragma comment(lib,"opencv_features2d231.lib")
    #pragma comment(lib,"opencv_flann231.lib")
    #pragma comment(lib,"opencv_gpu231.lib")
    #pragma comment(lib,"opencv_highgui231.lib")
    #pragma comment(lib,"opencv_imgproc231.lib")
    #endif
    int _tmain(int argc, _TCHAR* argv[])
    {
        
        IplImage * im_src = cvLoadImage("V100.jpg",CV_LOAD_IMAGE_GRAYSCALE);
        IplImage * im_show = cvCreateImage(cvGetSize(im_src),8,3);
        cvConvertImage(im_src,im_show);
        IplImage * im_threshold =cvCreateImage(cvGetSize(im_src),8,1);
        cvNot(im_src,im_src);
        cvThreshold(im_src,im_threshold,0,255,CV_THRESH_OTSU);
        cvShowImage("im_thresold",im_threshold);
        CvMemStorage *storage = cvCreateMemStorage(0);
        CvSeq * contour = NULL;
        cvFindContours(im_threshold,storage,&contour);
        float angle ;
        for (;contour!=0;contour=contour->h_next)
        {
            if (contour->total > 10)
            {
                CvBox2D ellipse = cvFitEllipse2(contour);
                cvEllipseBox(im_show,ellipse,CV_RGB(255,0,0));
                angle = ellipse.angle - 180
                printf("%f \n",ellipse.angle);
            }
        }
        
        IplImage * ration = cvCreateImage(cvGetSize(im_src),8,1);
        float m[6];
        CvMat M = cvMat( 2, 3, CV_32F, m );
        CvPoint2D32f pt = cvPoint2D32f(im_src->width/2.0, im_src->height/2.0);
        cv2DRotationMatrix(pt, angle, 1.0, &M);
        cvWarpAffine(im_src,ration,&M,CV_INTER_AREA |CV_WARP_FILL_OUTLIERS,cvScalarAll(0)); 
        cvNot(ration,ration);
        cvSaveImage("s.bmp",ration);
        cvShowImage("ration",ration);
        cvShowImage("show",im_show);
        cvWaitKey(-1);
        getchar();
        
        cvReleaseImage(&ration);
        cvReleaseImage(&im_threshold);
        cvReleaseImage(&im_src);
        return 0;
    }
     





  • 相关阅读:
    2017-9-8-Linux下VNC server开启&图形界面显示
    2017-9-8-RaspberryPi安装过程
    2017-9-7-Linux Mint TFTP服务安装开启
    2017-9-7-第一篇博客
    面试回答优缺点问题
    多层板的层叠和压合结构
    磁珠和电感
    关于TVS、ESD、稳压二极管、压敏电阻
    STM8硬件设计注意事项
    根据电路板画出电路原理图的方法
  • 原文地址:https://www.cnblogs.com/xiaomaLV2/p/2576319.html
Copyright © 2020-2023  润新知