zoukankan      html  css  js  c++  java
  • 从txt读取数据到Cvmat

    前提已经得到txt的行列数目:

    #include <cv.h>
    #include <highgui.h>
    #include <fstream> 
    #include <iostream>
    using namespace std;
    int main()
    {
    	ifstream myfile( "E:\\feature_size.txt "); 
    	if (!myfile.is_open()) 
    		cout << "Unable to open file";
    	int rows = 0,cols = 0;
    	myfile >> rows >> cols;
        //cout << f_m << " " << f_n;
    	//矩阵存取
        //ifstream feature_file( "E:\\features.txt ");
    	CvMat *fc = cvCreateMat(rows,cols,CV_32FC1);;
    	ifstream fin("E:\\features.txt ",std::ifstream::in);
    	for(int i = 0;i < rows; ++i)
    		for(int j = 0;j < cols; ++j)
    		{
    			fin >> fc->data.fl[i*cols+j];
    		}         
    		fin.close();
    		for(int i = 0;i < rows; ++i)
    			for(int j = 0;j < cols; ++j)
    		       cout << cvmGet(fc,i,j)<<" ";
    
    }
    

      

  • 相关阅读:
    Django第一天
    约束条件 表之间的关系
    数据类型
    初始vue
    JQ事件和事件对象
    Jquery的属性操作和DOM操作
    浏览器对象BOM
    Swiper实现全屏视觉差轮播
    Swiper开篇
    JSON
  • 原文地址:https://www.cnblogs.com/xiangshancuizhu/p/2215504.html
Copyright © 2011-2022 走看看