Image Fuzzy Recognition c ++ code based on opecv 3.1, opecv3.1

Source: Internet
Author: User
Tags mul

Image Fuzzy Recognition c ++ code based on opecv 3.1, opecv3.1

For opencv3.1 + windows10 + vs2015 configuration, see the article

How to configure Opencv3.1.0 in vs2015 in win10 (transfer)

The Code has been tested, and the recognition is extremely high. There are 50 million images and the recognition rate is over 90%.

If you can combine the Microsoft Oxford program's api to identify picture items https://www.azure.cn/projectoxford/demo/vision#Ocr

#include <stdio.h>#include <stdlib.h>#include <ctype.h>#include <iostream>#include "highgui.h"#include "cvaux.h"IplImage* praw;float VideoBlurDetect(IplImage* data){    int width=data->widthStep;    int height=data->height;    ushort* sobelTable = new ushort[width*height];    memset(sobelTable, 0, width*height*sizeof(ushort));    int i, j, mul;    uchar* udata = (uchar*)data->imageData;    for(i = 1, mul = i*width; i < height - 1; i++, mul += width)        for(j = 1; j < width - 1; j++)            sobelTable[mul+j]=abs(udata[mul+j-width-1] + 2*udata[mul+j-1] + udata[mul+j-1+width] -\            udata[mul+j+1-width] - 2*udata[mul+j+1] - udata[mul+j+width+1]);    for(i = 1, mul = i*width; i < height - 1; i++, mul += width)        for(j = 1; j < width - 1; j++)            if(sobelTable[mul+j] < 50 || sobelTable[mul+j] <= sobelTable[mul+j-1] ||\                sobelTable[mul+j] <= sobelTable[mul+j+1]) sobelTable[mul+j] = 0;    int totLen = 0;    int totCount = 1;    uchar suddenThre = 50;    uchar sameThre = 3;    for(i = 1, mul = i*width; i < height - 1; i++, mul += width)    {        for(j = 1; j < width - 1; j++)        {            if(sobelTable[mul+j])            {                int   count = 0;                uchar tmpThre = 5;                uchar max = udata[mul+j] > udata[mul+j-1] ? 0 : 1;                for(int t = j; t > 0; t--)                {                    count++;                    if(abs(udata[mul+t] - udata[mul+t-1]) > suddenThre)                        break;                    if(max && udata[mul+t] > udata[mul+t-1])                        break;                    if(!max && udata[mul+t] < udata[mul+t-1])                        break;                    int tmp = 0;                    for(int s = t; s > 0; s--)                    {                         if(abs(udata[mul+t] - udata[mul+s]) < sameThre)                        {                            tmp++;                            if(tmp > tmpThre) break;                        }                        else break;                    }                    if(tmp > tmpThre) break;                }                max = udata[mul+j] > udata[mul+j+1] ? 0 : 1;                for(int t = j; t < width; t++)                {                    count++;                    if(abs(udata[mul+t] - udata[mul+t+1]) > suddenThre)                        break;                    if(max && udata[mul+t] > udata[mul+t+1])                        break;                    if(!max && udata[mul+t] < udata[mul+t+1])                        break;                    int tmp = 0;                    for(int s = t; s < width; s++)                    {                        if(abs(udata[mul+t] - udata[mul+s]) < sameThre)                        {                            tmp++;                            if(tmp > tmpThre) break;                        }                        else break;                    }                    if(tmp > tmpThre) break;                }                count--;                totCount++;                totLen += count;            }        }    }    float result = (float)totLen/totCount;    delete[] sobelTable;    return result;}int main(){        //CvCapture* cvCreateCameraCapture(-1);            float re;    IplImage* praw=cvLoadImage("d:/123.jpg",CV_LOAD_IMAGE_GRAYSCALE);     re=VideoBlurDetect(praw);    std::cout<<re;    cvNamedWindow("Example",CV_WINDOW_AUTOSIZE);    cvShowImage("Example",praw);    cvWaitKey(0);    cvReleaseImage(&praw);    cvDestroyWindow("Example");    return 0;}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.