菜鸟第一次接触虚拟机及菜鸟的第一个类

这周重新系统学了下C++类部分。研一时总是看不懂的东西现在看懂了并慢慢深入,学得很带劲。以前从没接触过虚拟机,老板把他配置好的给我,我装上了,可以运行。我电脑是win7 64位的。我把他发给我的都放在一个目录下:https://pan.baidu.com/s/1jHISZTs  这个解压后放一个文件夹。  https://pan.baidu.com/s/1hr8NHOS 这个解压后有10个文件和另两个文件一起放一个文件夹  但另两个我传不上来 超过4G了 等哪次可以传上来了我再补充上来。

安装好以后出现图标:这就是应用程序了。

打开:


点击:开启此虚拟机:等待


输入用户名和密码之后进入:


双击打开出现

等待  出现:然后可以添加工程项目:File-New-C++project 再对创建的项目工程右击New-Folder :我创建了src文件夹专门用来放源文件等   看再这样创建src2文件夹

如这个工程:这是整个工程或者说workspace   然后右击setting:

第一在这里添加库:


第二继续添加库:


第三:继续添加需要用的库:


第一个lib是必须的。其它是根据实际程序添加。

另外在编写程序时窗口不够大 可以用快捷键Ctrl+Alt+Enter在全屏和还原之间切换 很方便!

当吃饭去了回来它锁屏了 按一下Enter输入密码就好了。

每次要运行时要先右击项目-Clean Project或者Build Project再按Ctrl+F11运行:


比如程序今天没编辑完 想明天继续编辑  那么可以将这个虚拟机挂起 下次打开就是直接这个界面:

变成 就OK了。

/

上两周重学C++的面向对象部分:第一个类  是根据图片用某个小算法判断是矿还是废石  统计矿的个数 将矿保存进一个文件夹 将废石也保存进一个文件夹 


类的实现部分:

#include "Myxiaowang.h"
#include <string>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace std;
using namespace cv;
#define allnum  (484 * 364)
char src_ipl[100];
char kuang_path[100];
char stone_path[100];

fluore::fluore(float thresh){
	threshold = thresh;
}
void fluore::get_imgs(char* src_folders,int src_num){
	string a = src_folders;
	a.append("\\%d.bmp");
	for (int i = 1; i <= src_num; i++){
		sprintf(src_ipl, a.c_str(), i);
		//sprintf(src_ipl, "front_B_fluore\\%d.bmp", i);
		Mat theimg = imread(src_ipl);
		imgs.push_back(theimg);
	}
}

void fluore::classify(){
	for (vector<Mat>::iterator i = imgs.begin(); i!=imgs.end(); i++){
		Mat srcimg = *i;
		int num = 0;
		for (int j = 0; j < srcimg.rows; j++){
			uchar* data = srcimg.ptr<uchar>(j);
			for (int i = 0; i < srcimg.cols; i++){
				if (data[i] == 255)
					++num;
			}
		}
		float ratio = (float)num / allnum;
		if (ratio >= threshold)
			classify_results.push_back(true);
		else
			classify_results.push_back(false);
	}
}

int fluore::return_number(){
	int allkuang = 0;
	for (vector<bool>::iterator it = classify_results.begin(); it != classify_results.end(); ++it){
		bool temp = *it;
		if (temp)
			++allkuang;
	}
	return allkuang;
}

void fluore::save_folders(char* kuang_folder, char* stone_folder){
	int kuangnum = 0;
	int stonenum = 0;
	string kuangstr = kuang_folder;
	string stonestr = stone_folder;
	kuangstr.append("\\%d.bmp");
	stonestr.append("\\%d.bmp");
	vector<Mat>::iterator i = imgs.begin();
	for (vector<bool>::iterator it = classify_results.begin(); it != classify_results.end();++it,++i)
	{
		bool temp = *it;
		Mat tempimg = *i;
		if (temp){
			++kuangnum;
			//sprintf(kuang_path, strcat(kuang_folder, "\\%d.bmp"), kuangnum);//这样strcat()是不对的 kuang_folder我给的是一个常量 后面的加进来地方不够
			sprintf(kuang_path, kuangstr.c_str(), kuangnum);
			imwrite(kuang_path, tempimg);
		}
		else
		{
			++stonenum;
			//sprintf(stone_path, strcat(stone_folder, "\\%d.bmp"), stonenum);
			sprintf(stone_path, stonestr.c_str(), stonenum);
			imwrite(stone_path, tempimg);
		}
	}
}

fluore::~fluore()
{
}
我本来将保存和判断放一个函数了  不对的   面向对象的单一性原则  一个成员函数就一个功能最好。

测试部分:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include "Myxiaowang.h"
#include <string>
using namespace std;
using namespace cv;
void main(){
	fluore myfluore(0.005);
	myfluore.get_imgs("front_B_fluore",364);//读图
	myfluore.classify();//分类
	int kuangnum = myfluore.return_number();//统计
	cout << kuangnum << endl;
	myfluore.save_folders("kuang", "stone");//保存
}
///菜鸟努力从面向过程向面向对象转变 争取尽快建立面向对象的编程思想



/

我同事给我一个VS2013的插件 https://pan.baidu.com/s/1miCZ4c4  这个在编写时 如果我定义了一个指针类型的对象  使用其函数时我用的.点操作符 那其实是不对的  但这个插件会自动换成->箭头操作符。很方便 当把这个插件放在VS安装目录并替换那个VA_X文件后  它就自动到VS界面去了:

就是这个东西。

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

元气少女缘结神

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值