zoukankan      html  css  js  c++  java
  • 计算image 积分图

     1 // testopencv.cpp : 定义控制台应用程序的入口点。
     2 //
     3 
     4 #include "stdafx.h"
     5 #include <opencv2opencv.hpp>
     6 #include <fstream>
     7 #include <vector>
     8 #include <string>
     9 using namespace std;
    10 using namespace cv;
    11 void getFileName(string & filename,vector<string> &vstr)
    12 {
    13     cout<<"begin read file name from "<< filename<<endl;
    14     string name;
    15     ifstream in(filename);
    16     while(!in.eof())
    17     {
    18         in>>name;
    19         vstr.push_back(name);
    20     }
    21     cout<<"end read filename , the total image number is "<< vstr.size()<<endl;
    22 }
    23 void writeIntegral(vector<string> &vstr,string& filename)
    24 {
    25     cout<<"begin calculate the image integral"<<endl;
    26     ofstream out(filename,ofstream::binary);
    27     int num = 0;
    28     vector<string>::iterator begin = vstr.begin();
    29     for( ;begin != vstr.end(); begin++)
    30     {
    31         //第二个参数为0读进来的image都是灰度的
    32         Mat img = imread(*begin,0);
    33         if(img.empty())
    34         {
    35             cout<<"read image "<<*begin<<" failed"<<endl;
    36             continue;
    37         }
    38         num++;
    39         Mat gray_img;
    40  
    41         CvMat sour_image=gray_img;
    42         CvMat *inte_image = cvCreateMat(gray_img.rows+1,gray_img.cols+1,CV_32F);
    43         cvIntegral(&sour_image,inte_image);
    44 
    45         
    46         float *f = inte_image->data.fl;
    47     
    48         out.write((char*)(f),inte_image->width*inte_image->height*sizeof(float));
    49     }
    50     out.close();
    51     cout<<"total image:"<<vstr.size()<<" cvIntegral number:"<<num<<endl;
    52 }
    53 int _tmain(int argc, _TCHAR* argv[])
    54 {
    55     vector<string> v;
    56     getFileName(string("face.txt"),v);
    57     writeIntegral(v,string("face.dat"));
    58     waitKey();
    59     return 0;
    60 }
  • 相关阅读:
    iPhone X 适配手机端 H5 页面通用解决方案
    创建cordova项目
    UltraEdit mac破解版
    ionic 和cordova的区别是什么
    还在为AndroidStudio的Gradle版本配置头疼?看看老司机的解决方法吧
    java final
    死锁产生的条件+排除死锁的方法
    String str=new String("a")和String str = "a"有什么区别?
    重载和覆盖的区别?(overload vs override)
    深拷贝和浅拷贝
  • 原文地址:https://www.cnblogs.com/churi/p/4000665.html
Copyright © 2011-2022 走看看