初学opencv的点滴积累

本文介绍了OpenCV中不同图像数据类型之间的转换方法,并提供了一种动态格式化字符串的实用技巧,同时分享了如何在C++中高效地构建多维矩阵。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、关于在CvMat 、Mat、IplImage之间的转换,参考此链接:

1. http://www.cnblogs.com/Key-Ky/p/4150531.html

2. http://blog.sina.com.cn/s/blog_7462bf390101c88a.html

第二个链接中第二个办法使用会报错,正确方式是:

(此为Mat转IplImage*)

            Mat src;

            IplImage srcImg =IplImage(src); 
            IplImage* gray = cvCreateImage(cvGetSize(&srcImg), IPL_DEPTH_8U, 1);


二、动态格式化字符串

如果是 basic_string型,使用ostringstream,声明#include <sstream>

   vector<std::vector<string> >  m_fileNames;

    m_fileNames.resize(3);

    for (int i = 0; i < 3; ++i)
    {
        m_fileNames[i].resize(3);
    }

    for (int i = 0; i < 3; ++i)
    {

        for (int j = 0; j < 3; ++j)
        {
            std::string strFilePath = "/home/ctt/Project/Qt/face_lbp_ctt/face_lbp_ctt/Faces/s";
            ostringstream stri; //string 格式化字符串
             stri.str("");
             stri << strFilePath << i+1 << "/" << j+1 << ".BMP";

             strFilePath=stri.str();

   //             cout<<strFilePath<<endl;

            m_fileNames[i][j] = strFilePath;

        }
    }

http://blog.youkuaiyun.com/James506/article/details/1548935

三、单行赋值给Mat矩阵,即合并n个长度为m的一维向量,最后是n*m。

参考http://blog.youkuaiyun.com/yanzi1225627/article/details/7687310




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值