C++ 学习之路 (7)一个类调用其他类的成员变量或函数

我的目录结构如下: 

因为我在使用的是OpenCV ,所以项目里面的 头文件:#include <opencv2/opencv.hpp> 和命名空间 using namespace cv;

你直接删了就行,不然你直接把我代码复制过去会报错的,我这里只是告诉大家怎么调用其他类的函数

1.    stdafx_h 常用的库文件

//
//  stdafx.h
//  FirstCTest
//
//  Created by lishengfu on 2018/12/2.
//  Copyright © 2018 lishengfu. All rights reserved.
//

#ifndef stdafx_h
#define stdafx_h
#include <iostream>
#include <opencv2/opencv.hpp>
#include "OpenCVFunction.hpp"

using namespace cv;
using namespace std;

#endif /* stdafx_h */

2.   OpenCVFunction_hpp

//
//  OpenCVFunction.hpp
//  FirstCTest
//
//  Created by lishengfu on 2018/12/2.
//  Copyright © 2018 lishengfu. All rights reserved.
//

#ifndef OpenCVFunction_hpp
#define OpenCVFunction_hpp

#include <stdio.h>

#endif /* OpenCVFunction_hpp */
class OpenCVFunction{
public:
    OpenCVFunction();
    ~OpenCVFunction();
    public :
    bool ROI_AddImage();
    int num;
private:
    
    
};

3.     OpenCVFunction.cpp

//
//  OpenCVFunction.cpp
//  FirstCTest
//
//  Created by lishengfu on 2018/12/2.
//  Copyright © 2018 lishengfu. All rights reserved.
//


#include "stdafx.h"

OpenCVFunction::OpenCVFunction(){
    
}
OpenCVFunction::~OpenCVFunction(){
    
}
//----------------------------------【ROI_AddImage( )函数】----------------------------------
// 函数名:ROI_AddImage()
//     描述:利用感兴趣区域ROI实现图像叠加
//----------------------------------------------------------------------------------------------

bool OpenCVFunction::ROI_AddImage(){
    Mat srcImage = imread("/Users/administrator/Desktop/cool.jpg");
    Mat logoImage = imread("/Users/administrator/Desktop/hackerLogo.jpg");
    if (  srcImage.empty()) cout<< "srcImage null";
    if (  logoImage.empty()) cout<< "logoImage null";
    
    //【2】定义一个Mat类型并给其设定ROI区域
    Mat srcImageROI = srcImage(Rect(50,50,logoImage.cols,logoImage.rows));
    cout<<logoImage.cols<<endl;
    cout<<logoImage.rows<<endl;
    //【3】加载掩模(必须是灰度图)
    Mat mask= imread("/Users/administrator/Desktop/hackerLogo.jpg",0);
    
    logoImage.copyTo(srcImageROI,mask);
    namedWindow("srcImage",CV_WINDOW_AUTOSIZE);
    imshow("srcImage",srcImage);
    imshow("mask",mask);
    return  true;
}

4.    main.cpp

//
//  main.cpp
//  FirstCTest
//
//  Created by lishengfu on 2018/11/29.
//  Copyright © 2018 lishengfu. All rights reserved.
//

#include "stdafx.h"

int main() {
    // insert code here...
    OpenCVFunction *cv=new OpenCVFunction();
    cv->ROI_AddImage();

    waitKey(60000);
    return 0;
}

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值