-
Notifications
You must be signed in to change notification settings - Fork 2
/
OpenCG.cpp
96 lines (72 loc) · 2.81 KB
/
OpenCG.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//入口函数
#include "OpenCG.h"
#include "opencv2/opencv.hpp"
#include "persondetectorwt.tcc"
using namespace CG;
using namespace cv;
#if (!defined USING_CMAKE)
#pragma comment( lib, "opencv_core244d.lib" )
#pragma comment( lib, "opencv_highgui244d.lib" )
#pragma comment( lib, "opencv_imgproc244d.lib" )
#endif
Mat onMouseImg;
char dispChar[20];
void on_mouse(int event, int x,int y,int flags,void* param)
{
if(event==CV_EVENT_MOUSEMOVE)//鼠标状态
{
Mat dispImg;
cvtColor(onMouseImg, dispImg, CV_GRAY2RGB);
int gray = *(onMouseImg.data+y*(onMouseImg.cols)+x);
sprintf(dispChar,"x:%d, y:%d, gray:%d",x, y, gray);
putText(dispImg,dispChar,Point(x,y), CV_FONT_HERSHEY_COMPLEX, 0.5 ,cvScalar(255,255,0));
imshow("result",dispImg);
}
}
int main()
{
Mat m_Image = imread("1.bmp", CV_LOAD_IMAGE_GRAYSCALE);
resize(m_Image, m_Image, Size(641, 479) );
m_Image.convertTo(m_Image,CV_32FC1,1.0/255);
imshow("source", m_Image);
//////////////////////////////////
//新建ImgIn,并从Mat中拷贝数据
CG::Core::CGImage<float> *ImgIn = new CG::Core::CGImage<float>(m_Image.cols, m_Image.rows);
CG::Core::CGImage<float> *ImgDst = new CG::Core::CGImage<float>(m_Image.cols, m_Image.rows); //normal
//CG::Core::CGImage<float> *ImgDst = new CG::Core::CGImage<float>((m_Image.cols / 4 - 1)*2*9, (m_Image.rows / 4 - 1)*2); //histogram
//CG::Core::CGImage<float> *ImgNorm = new CG::Core::CGImage<float>(m_Image.cols, m_Image.rows);
//CG::Core::CGImage<float> *ImgGrad = new CG::Core::CGImage<float>(m_Image.cols, m_Image.rows);
float *imgData = ImgIn->GetData(false);
memcpy(imgData, (float*)m_Image.data, m_Image.cols * m_Image.rows * sizeof(float));
ImgIn->UpdateDeviceFromHost();
//////////////////////////////////
long s_t = getTickCount();
//_sleep(10000);
//CG::Core::CGFilter(ImgDst, ImgIn, 0.1, 10, 1);
CG::Core::CGDwtHaar(ImgDst, ImgIn, 2);
//CG::Core::CGComputeGradient(ImgDst, ImgIn);
//CG::Core::CGPyramid(ImgDst, ImgIn, 1.73);
////histogram
//CG::Core::CGPyramid(ImgIn, ImgIn, 1.73);
//CG::Core::CGComputeGradNorm(ImgGrad, ImgNorm, ImgIn);
//CG::Hog::cgInitHistogram();
//CG::Hog::CGHogHistogram(ImgDst, ImgGrad, ImgNorm);
////svmScore
//std::vector<HogResult> hogResult;
//CG::Hog::cgHogInit(PERSON_LINEAR_BIAS, PERSON_WEIGHT_VEC, PERSON_WEIGHT_VEC_LENGTH);
//CG::Hog::CGHogExecute(hogResult, ImgIn);
long e_t = getTickCount();
printf("%d", (e_t - s_t)/2500);
////////////////////////////////////
ImgDst->UpdateHostFromDevice();
Mat resultImg(ImgDst->hight, ImgDst->width, CV_32FC1, ImgDst->GetData(false));
resultImg.convertTo(resultImg, CV_8UC1, 255);
onMouseImg = resultImg;
namedWindow("result", 1);
imshow("result", resultImg);
cvSetMouseCallback("result",on_mouse); //鼠标回调,调试用
cvWaitKey();
ImgIn->Free();
ImgDst->Free();
return 0;
}