
C/C++学习
文章平均质量分 81
libin88211
这个作者很懒,什么都没留下…
展开
-
OJ练习题
1十六进制转成十进制显示 char a[10]; gets_s(a); int len = strlen(a); int sum = 0, int weight = 1; for(int i=len-1;i>1;i--) { if(a[i]>='0' &&a[i]<='9') { sum=sum+(a[i]-48)*weight; weight=weight原创 2015-04-29 21:57:13 · 1196 阅读 · 0 评论 -
结构体用法总结
一,定义简单结构体时可以对一些简单的函数定义、运算符进行重载,其实这是C++类的特性,但比类更加轻量级,且为后续处理提供了非常大的方便。如下例对>号进行重载方便了时间的比较。活学活用C/C++;struct Time{ int h,m,s; bool operator>(const Time a)const { if(a.h==h&&a.m==m) retur原创 2015-01-24 16:47:46 · 660 阅读 · 0 评论 -
opencv2学习_1从C风格转向C++
opencv2 之后的版本都是基于C++的,对于习惯使用C风格的朋友们来说很不适应。比如图片的数据结构都发生了巨大的变化。我们熟悉的IPlimage 结构将觅不的踪影。原创 2015-01-24 17:07:58 · 722 阅读 · 0 评论 -
自己写的Kmeans
#include #include #include#include#include "fstream"using namespace std;typedef struct Point{ double x; double y; int label;}Point;class Sample{ public: Sample(const string& file_原创 2015-01-24 16:55:13 · 570 阅读 · 0 评论 -
opencv2中MSER区域提取
opencv 更新速度一直在加快,最新版本都出到了3.0beta了。MSER一直在用C接口的,最近想试一下3.0的MSER,发现还用不起来,因为封装方法还没搞清楚,也没有太多参考,就用了Qt5.3+opencv2.4.7中的C++接口MSER,当然没有界面,还是控制台程序。总的来说还是比较方便的。#include #include "opencv2/core/core.hpp"#inclu原创 2015-01-26 09:08:58 · 3193 阅读 · 0 评论 -
给RGB加上BMP文件头
需要将摄像头采集到的图像数据(纯净的RGB,或BGR数据)加上文件头后暂存在内存中如若写入文件仅需将memcpy换成fwrite即可。#ifndef RGB2BMP_H#define RGB2BMP_H///为拍摄的RGB数据加上BMP文件头///作者:/// 2014.6.25///typedef unsigned char BYTE;typedef unsigned s原创 2015-01-24 16:53:22 · 1549 阅读 · 0 评论 -
常用C++函数模板整理
1:数值交换 template static inline void swap(T& x, T& y) { T t=x; x=y; y=t; }原创 2015-01-17 15:51:48 · 582 阅读 · 0 评论 -
C++读取文件txt中double型内容
ifstream ifstr_man("GMM-data//man.txt");//读取文本数据 一列;// ifstream ifstr_woman("GMM-data//woman.txt"); //读取文本数据 一列;// double d; while (ifstr_man >> d) sample.push_back(d);//将数据压入堆栈。// while (ifst原创 2015-01-29 16:27:06 · 9031 阅读 · 0 评论 -
360笔试2014-10-11
第一部分,四十道选择题基础知识,前五道是原创 2014-10-11 21:30:35 · 1484 阅读 · 0 评论 -
MFC 下调用Qt编写的含界面的dll
接到任务要做一个既可以在纠结了好几天了,原创 2014-07-27 23:23:57 · 18868 阅读 · 14 评论 -
test
dafsdfasd原创 2015-04-30 19:43:14 · 476 阅读 · 0 评论 -
zookeeper C API
#include #include #include #include "include/zookeeper/zookeeper.h"#include "include/zookeeper/zookeeper_log.h"//void zktest_watcher_g(zhandle_t* zh, int type, int state,// const char*原创 2015-05-03 22:49:05 · 597 阅读 · 0 评论 -
数字转字符串
template <typename T> static std::string num2str(T v) { std::ostringstream oss; oss << v; return oss.str(); }原创 2018-07-18 22:37:19 · 854 阅读 · 0 评论 -
days
/*储存12个月的天数*/const int days[12]={31,28,31,30,31,30,31,31,30,31,30,31};/*判断是否为闰年*/int isLeapYear(int year){ if(((year%4==0)&&(year%100!=0)) ||(year%400==0)) { return 1; } return 0;}i原创 2015-08-16 20:56:15 · 636 阅读 · 0 评论 -
自守数判断
#include #includeint getNum(long num){ int count = 0; while(num) { num/=10; count++; } return count;}int mypow(int n){ int p=1; int i; for(i= 0;原创 2015-07-17 22:03:25 · 1619 阅读 · 0 评论 -
vote
#include #include#includeusing namespace std;map candidaes;typedef map::iterator VstrItor;int invild =0;unsigned int Addcandidate(char* pCandidateName){ if(NULL == pCandidateName ) {原创 2015-07-17 22:51:00 · 876 阅读 · 0 评论 -
时间函数
#include #include #include #includeusing namespace std;time_t GetTimeStampByStr( const char* pDate ){ const char* pStart = pDate; char szYear[5], szMonth[3], szDay[3], szHour[3],原创 2015-07-16 23:30:21 · 623 阅读 · 0 评论 -
文件操作——日期排序
#include #include #include #include using namespace std;#define MAXLINELENGTH 20#define YEAR 1970typedef struct DATE{ int year; int month; int day; int hour; int min; int sec;} DATE;原创 2015-07-14 23:16:17 · 600 阅读 · 0 评论 -
文件读写
#include #include #include #define MAXLINELENGTH 10void fileCopy(FILE *pfin,FILE *fout){ //复制第一行内容 char buffer[MAXLINELENGTH]={'\0'}; fgets(buffer,MAXLINELENGTH,pfin); printf("fil原创 2015-07-12 23:40:28 · 504 阅读 · 0 评论 -
oj 题(二)
句子翻转,单词翻转// HuaweiOJ.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include #includeusing namespace std;int converse(char* str,char* end){ if(NULL == str||NULL == end ) { return -1; }原创 2015-05-03 19:21:17 · 477 阅读 · 0 评论 -
MSER_sample
// mser.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include "opencv2/highgui/highgui.hpp"#include "opencv2/features2d/features2d.hpp"#include "opencv2/imgproc/imgproc_c.h"#include void help()原创 2014-07-01 14:45:45 · 1030 阅读 · 0 评论 -
给图像数据加上BMP文件头
需要将摄像头采集到的图像数据原创 2014-07-01 14:51:34 · 4950 阅读 · 0 评论 -
vector类的resize和reserve方法
vector 的reserve增加了vector的capacity,但是它的size没有改变!而resize改变了vector的capacity同时也增加了它的size!原因如下: reserve是容器预留空间,但在空间内不真正创建元素对象,所以在没有添加新的对象之前,不能引用容器内的元素。加入新的元素时,要调用push_back()/insert()函数。 resiz转载 2014-05-21 17:19:19 · 812 阅读 · 0 评论 -
DPM样本生成——字符转换
// DPMSample.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include #include #include #include #include #include "cv.h"#include "cxcore.h"#incl原创 2014-01-08 14:42:00 · 885 阅读 · 0 评论 -
图像缩放
高深的搞不动了搞些简单的// Gauss.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include "cv.h"#include "highgui.h"#include ;#include using namespace std;void resizeIma原创 2014-01-07 20:17:12 · 832 阅读 · 0 评论 -
递归方法
从大二开始学习C语言,记得当时书上的练习题有一道是关于汉诺塔的,真么也搞不明白,只有少数个圆盘的时候能够想象出来如何去实现,但情况以多立马头都大了,看了看网上有说用递归的方法比较简单,但是递归,一直觉得是高深莫测的东东,老师从来没有给我讲明白过,自己也是很苦恼 ,计算机技术中如此重要的内容居然搞不明白。 后来也就没有再在编程方面深入下去,大三在搞硬件,大四考研,直到研究生了原创 2014-01-01 22:26:27 · 692 阅读 · 0 评论 -
拓扑排序
拓扑排序// tuopupaixu.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include #include #include using namespace std;typedef struct{ char w1,w2; float w原创 2013-12-29 15:51:05 · 852 阅读 · 0 评论 -
Opencv 用SVM训练检测器
用svm+HOG 训练检测器,可以在图像上进行扫描检测。#include "stdafx.h"// mypro.cpp : Defines the entry point for the console application.//#include "cv.h"#include "highgui.h"#include #include #include #include #inc原创 2013-12-02 16:52:47 · 1789 阅读 · 0 评论 -
C++中测试某算法耗时的方法
#include clock_t clockBegin, clockEnd;void PrintfContainerElapseTime(char *pszContainerName, char *pszOperator, long lElapsetime) { printf("%s 的 %s操作 用时 %d毫秒\n", pszContainerName, pszOperat原创 2013-10-08 17:14:13 · 2049 阅读 · 1 评论 -
matlab 中 rectint()函数的C版本
matlab中有名为rectint的函数功能是判断同一坐标系下两个矩形是否相交,返回交叠部分的面积大小,比较好用,且能用于多对矩形一起判断。最近仿照其改写了个C版本的,简单但很实用,一次判断一对矩形。参数为自定义的rect 结构体;struct rect{ int upleftx; int uplefty; int downrightx; int downrighty;原创 2013-06-02 14:33:07 · 2367 阅读 · 0 评论 -
C中可变参数函数
今天接触到C语言中的可变参数函数,回想C已经学了那么久,今天看到一段代码包含一个陌生的头文件“#include stdarg.h”知道它是标准库中的头文件疑惑它是用来干什么的。搜索了一下:可变参数函数的参数数量是可变动的,它使用省略号来忽略之后的参数。例如printf函数一般。代表性的声明为:int check(int a, double b, ...);成员stdarg.h数据类型类型名称描述相原创 2013-04-16 08:55:13 · 715 阅读 · 0 评论 -
C++图片批处理
在图像处理过程中,经常要对图像进行缩放以减少数据量,加快处理速度,试过创建一个txt文件,其中存放文件列表(在dos下用dir/b 命令生成)但过程较为复杂,此处方法较为简单,但是要事先将要处理的图片按数字顺序命名,比如"1.jpg,2.jpg"等等。当然处理不仅限于图片尺度变化,还可以进行其他的常规操作,所以也是一个十分有用的简单的工程。可以批量处理图片。 工程目录下创建src_i原创 2013-04-14 07:25:17 · 2244 阅读 · 0 评论 -
opencv2.3.1+vs2010摄像头驱动
记得在大一的时候就有一些想法:用程序去驱动硬件工作。比如摄像头,马达,齿轮,显示器等等,后来学了一段单片机也可以用它来控制一些简单的东西,再后来考研了,把单片机,arm束之高阁了,很久了,很多都遗忘了,但是这些想法还一直萦绕在心头,由于搞了图像处理这一行,所以就一直想着去驱动摄像头工作,采集图像,之前没有涉及都是用的国外的图像库进行处理的,一直也想尝试一下用程序控制一下摄像头,原来opencv里面原创 2013-04-08 21:22:47 · 1497 阅读 · 0 评论 -
dijkstra算法详细分析
// dijkstra.cpp : Defines the entry point for the console application.//#include "stdafx.h"//狄杰斯特拉算法寻找图中的最短距离//#include #include "stdio.h"#include "stdlib.h"#include #inclu原创 2014-01-08 21:57:45 · 1157 阅读 · 0 评论 -
纯属练手
// L2norm.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include #include using namespace std;typedef struct { int rows; int cols; float* data;}Matri原创 2014-01-09 15:15:31 · 651 阅读 · 0 评论 -
字符串转整形
int StrToDecInt1(const char* str){ static const int MAX = (int)((unsigned)~0 >> 1);//32位能表示的最大的正整数// static const int MIN = -(int)((unsigned)~0 >> 1) - 1;//最小负整数// static const int MAX_DIV = (int)转载 2014-05-13 11:12:50 · 803 阅读 · 0 评论 -
交通标志红孔检测法
哈工大博士王刚毅论文中提到红孔检测法,lun原创 2014-05-19 10:53:49 · 1236 阅读 · 1 评论 -
MFC中使用多个timer定时器
1,在MFC中添加WM_TIMER消息处理函数会生成 void CFaceDetectDlg::OnTimer(UINT_PTR nIDEvent)原创 2014-05-10 16:55:39 · 9203 阅读 · 0 评论 -
opencv 视频处理框架,面向对象,简单实用,可扩展
头文件/*------------------------------------------------------------------------------------------*\ This file contains material supporting chapter 10 of the cookbook: Computer Vision Progr原创 2014-03-21 18:02:13 · 853 阅读 · 0 评论 -
opencv 中图像处理的一般流程——面向对象
图像处理算法opencv实现的通用框架,很实用,总结如下。将要处理的图片当做参数传递给算法类,每个算法都做一个类算法类的定义 1.必要的参数,参数的set,get函数; 2.必要的辅助函数,尽量拆分开来,功能独立,短小; 3. 输出图像作为成员变量,处理结果通过其返回 class GetColor{priv原创 2014-03-09 20:20:05 · 2964 阅读 · 1 评论