项目 / 杭州

img

0.Github资源

1.引脚选择

img
img

  • 实际连接引脚
    img
    img

2.main()函数

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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <iostream>
#include <dcamera.h>
#include <xmlreader.h>
#include <XMLWriter.h>
#include <string.h>
#include <gpioset.h>
#include <unistd.h>

using namespace std;
int scanFiles(vector<string> &fileList, string inputDirectory);
std::string filename = "/home/nvidia/config.xml";
std::string filenameImg = "/home/nvidia/config_imgSize.xml";

std::string inputDirectory = "/media/nvidia";

//float imgSize = 36.8;


int main()
{
gpio_set_dir(246,"out");
gpio_set_value(246,0);
//Windows close time
sleep(2);

string CamIndex;
float shutter = 0;
float gain = 0;
int CamWaitTime = 0;
int OnceImgSize = 0;

int imgSize = 0;
XMLReader::ReadCamParams(filename,CamIndex,shutter,gain,CamWaitTime,OnceImgSize);
shutter = shutter*10000;
XMLReader::ReadImgSize(filenameImg, imgSize);
cout<<"Now img can save: "<<imgSize << endl;
if(imgSize <= OnceImgSize){
cout << "Memory is full!!!"<<endl;
system("poweroff");

return 0;
}
int imgNowSize = imgSize - OnceImgSize;
XMLWriter::WriteLaserSystemConfig(filenameImg, imgNowSize);
//XMLWriter::WriteLaserSystemConfig(filenameImg, );
//XMLReader::ReadImgSize(filenameImg, );


GX_OPEN_PARAM CAM;
CAM.accessMode = GX_ACCESS_EXCLUSIVE;
CAM.openMode = GX_OPEN_SN;
char* c = const_cast<char *>(CamIndex.c_str());
CAM.pszContent = c;

DhCamera cam;
std::queue<cv::Mat> imaQue;
if(!cam.ConnectCamera(&CAM,imaQue,shutter,gain)){
cout<<"Camera initial error!"<<endl;
return 0;
}

cv::Mat imgTemp;
vector<string> fileList;
int Num123 = scanFiles(fileList,inputDirectory);
if(Num123 != 1){
cout<< "SD size error!"<<endl;
return 0;
}

int Nsize = OnceImgSize;
string nameA = inputDirectory + "/" + fileList[0]+ "/";
string getTime;
while(Nsize--){
//GPIO Light
gpio_set_value(246,1);
usleep(100);
cam.GrabAImg(imgTemp,1);

getTime = get_time();
cout<< getTime << endl;
imwrite(nameA + getTime + ".bmp",imgTemp);
gpio_set_value(246,0);

sleep(CamWaitTime);
}
cout << "Work has done!!!" << endl;
system("poweroff");

return 0;
}


int scanFiles(vector<string> &fileList, string inputDirectory)
{
inputDirectory = inputDirectory.append("/");

DIR *p_dir;
const char* str = inputDirectory.c_str();

p_dir = opendir(str);
if( p_dir == NULL)
{
cout<< "can't open :" << inputDirectory << endl;
}

struct dirent *p_dirent;

while ( p_dirent = readdir(p_dir))
{
string tmpFileName = p_dirent->d_name;
if( tmpFileName == "." || tmpFileName == "..")
{
continue;
}
else
{
fileList.push_back(tmpFileName);
}
}
closedir(p_dir);
return fileList.size();
}
文章作者: Inter
文章链接: https://zuizichuan.cn/2020/09/19/%E9%A1%B9%E7%9B%AE-%E6%9D%AD%E5%B7%9E/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Zichuan365' Blog