zoukankan      html  css  js  c++  java
  • 图片模糊度判断程序(C++、opencv)

    //#include<opencv2opencv.hpp>
    //using namespace cv;
    
    #include <opencv2/core/core.hpp>
    #include <opencv2/imgproc/imgproc.hpp>
    #include <opencv2/highgui/highgui.hpp>
    #include <iostream>
    #include "cv.h"
    
    using namespace cv;
    using namespace std;
    
    double focus(IplImage* image);
    
    int main()
    {
        IplImage*previous1;
        IplImage*previous2;
        IplImage*previous3;
        IplImage*previous4;
        previous1 = cvLoadImage("D:/2222/1 (1).jpg", 1);
        previous2 = cvLoadImage("D:/2222/1 (2).jpg", 1);
        previous3 = cvLoadImage("D:/2222/1 (3).jpg", 1);
        previous4 = cvLoadImage("D:/2222/1 (4).jpg", 1);
        if (previous1 != 0 && previous2 != 0 && previous3 != 0 && previous4 != 0) {
            cvNamedWindow("previous1", 1);
            cvShowImage("previous1", previous1);
            cvNamedWindow("previous2", 1);
            cvShowImage("previous2", previous2);
            cvNamedWindow("previous3", 1);
            cvShowImage("previous3", previous3);
            cvNamedWindow("previous4", 1);
            cvShowImage("previous4", previous4);
            cout << "The definition of the previous1 is: " << focus(previous1) << endl;
            cout << "The definition of the previous2 is: " << focus(previous2) << endl;
            cout << "The definition of the previous3 is: " << focus(previous3) << endl;
            cout << "The definition of the previous4 is: " << focus(previous4) << endl;
    
            //关掉窗口,结束   cvWaitKey(0);  
            cvDestroyWindow("previous1");
            cvReleaseImage(&previous1);
    
            cvDestroyWindow("previous2");
            cvReleaseImage(&previous2);
            cvDestroyWindow("previous3");
            cvReleaseImage(&previous3);
            cvDestroyWindow("previous4");
            cvReleaseImage(&previous4);
            return 0;
        }
        return -1;
    
    
    }
    double focus(IplImage*image) {
        IplImage*picone = cvCreateImage(cvGetSize(image), 8, 3);
        cvCvtColor(image, picone, CV_BGR2YCrCb);
        CvScalar gety;
        double z = 0, zy1 = 0, zy2 = 0, total = 0;
        double gety1 = 0, gety2 = 0;
        double final = 0;
        for (int ix = 0; ix < (picone->height); ix++) {
            gety1 = 0;
            gety2 = 0;
            zy1 = 0;
            zy2 = 0;
            for (int jy = 0; jy < (picone->width); jy++) {
                gety = cvGet2D(picone, ix, jy);
                z = 0.5*gety.val[0] - gety1 + 0.5*gety2 + zy1 - 0.5*zy2;
                total = total + z;
                gety2 = gety1;
                gety1 = gety.val[0];
                zy2 = zy1;
                zy1 = z;
            }
        }
        cvReleaseImage(&picone);
        final = abs(total / ((image->height)*(image->width)));
        return final;
    }
  • 相关阅读:
    React Native 安卓 程序运行报错: React Native version mismatch(转载)
    RN用蓝牙接入热敏打印机和智能电子秤(转载)
    安装加密用包
    React Native 调用 Web3(1.x) 的正确姿势
    Unable to resolve module crypto
    点击<tr>表格行元素进行跳转
    Phonegap环境配置
    登录记住密码功能的实现
    php+sqlserver实现分页效果
    php日期格式转换
  • 原文地址:https://www.cnblogs.com/zangdalei/p/5339353.html
Copyright © 2011-2022 走看看