-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParkingSpot.h
318 lines (254 loc) · 7.36 KB
/
ParkingSpot.h
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
// File: ParkingSpot.h
// Author: Seongdo Kim
// Contact: [email protected]
//
// Copyright (c) 2017, Seongdo Kim <[email protected]>
// All rights reserved.
// The copyright to the computer program(s) herein is
// the property of Seongdo Kim. The program(s) may be
// used and/or copied only with the written permission
// of Seongdo Kim or in accordance with the terms and
// conditions stipulated in the agreement/contract under
// which the program(s) have been supplied.
//
// Written by Seongdo Kim <[email protected]>, June, 2017
#pragma once
#include <string>
#include <opencv2/opencv.hpp>
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include <boost/asio/deadline_timer.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include "MessageQueue.h"
#include "SerialVideoReader.h"
namespace seevider {
class ParkingSpot {
public:
/**
* The read-only rectangular ROI
*/
const cv::Rect& ROI;
int pConf;
int cConf;
/**
* The read-only time limit as minutes
*/
const int& TimeLimit;
/**
* The read-only server-synchronized ID of the parking spot
*/
const int& ID;
/**
* The read-only server-synchronized human-friendly name of the parking spot
*/
const std::string& SpotName;
/**
* The read-only pre-defined parking policy
*/
const PARKING_SPOT_POLICY& ParkingPolicy;
/**
* (read-only) Designate if the system needs to update this parking spot
*/
const bool &UpdateEnabled;
std::string mPlateNumber;
std::string mCarBrand;
private:
/* result of recognized plate number of spot */
/**
* The original rectangular ROI
*/
cv::Rect mROI;
cv::Rect pROI;
cv::Rect vROI;
/**
* Time limit as minute
*/
int mTimeLimit;
/**
* The server-synchronized ID of the parking spot
*/
int mID;
/**
* The server-synchronized human-friendly name of the parking spot
*/
std::string mSpotName;
/**
* The pre-defined parking policy
*/
PARKING_SPOT_POLICY mParkingPolicy;
/**
* Set to be true if the system needs to update this parking spot
*/
bool mUpdateEnabled;
/**
* Must be true if the parking spot is occupied
*/
bool mOccupied;
/**
* True if the spot is overstayed
*/
bool mOverstayed;
/**
* Frame counter represents the occurence of occupancy events.
*/
int mOccupiedFrameCounter = 0;
/**
* Designate if the entry image is uploaded to the server.
*/
bool mIsEntryImageUploaded;
/**
* Designate if the exit image is uploaded to the server.
*/
bool mIsExitImageUploaded;
/**
* IO Service object for the deadline timer
*/
boost::asio::io_service mService;
/**
* Work object for the deadline timer
*/
boost::asio::io_service::work mWork;
/**
* Timer thread
*/
boost::thread mTimerThread;
/**
* Timer to check if the parking expires
*/
boost::asio::deadline_timer mParkingTimer;
/**
* Entry time to compute expiration when the timer is expired.
*/
boost::posix_time::ptime mEntryTime;
public:
/**
* Basic constructor.
* @params entryImage The original image taken at the time of entry.
* Only a clone of the image will be stored.
* @param length Allowed length of time for this parking spot
*/
ParkingSpot(int id, std::string spotName, const int length, const cv::Rect roi, PARKING_SPOT_POLICY policy);
/**
* Basic destructor
*/
~ParkingSpot();
//jeeeun
/*get set mPlateNumber*/
void setPlateNumber(std::string plate);
std::string getPlateNumber();
/*get set mCarBrand*/
void setCarBrand(std::string brand);
std::string getCarBrand();
/**
* Check if the parking spot is occupied
*/
bool isOccupied() const;
void pullDB();
/**
* Check if the parking spot is occupied and overstayed
*/
bool isOverstayed() const;
///////////////////////////////
void connect_DB();
int entVehicle(const std::string PN, const std::string entryTime);
bool check_res(const std::string PN);
bool isReservation_sensor;
bool isSensor();
void isRes_sensor();
///////////////////////////////
/**
* juhee add
*/
void setLocalizerROI(cv::Rect roiP);
void setVehicleROI(cv::Rect roiV);
cv::Rect getLocalizerROI();
cv::Rect getVehicleROI();
//jeeeun
std::string lpr_docker_server(const cv::Mat& cropImage);
/**
* Must be called when the vehicle comes in.
*/
void enter(const cv::Mat& entryImage, const cv::Rect &ROI, const boost::posix_time::ptime &entryTime, const std::string PN = "null");
/**
* Must be called when the maximum allowed time has reached.
*/
void overstayed(const cv::Mat& expiredImage, const boost::posix_time::ptime &exprTime);
/**
* Must be called when the vehicle goes out.
*/
void exit(const cv::Mat& exitImage, const boost::posix_time::ptime &exitTime, const std::string PN);
/**
* Update parking spot attributes. If current spot is occupied and the timer is running,
* it will not update the spot and return false.
*/
bool update(std::string spotName, int timeLimit, cv::Rect roi, PARKING_SPOT_POLICY policy);
/**
* Update current status. Return true if the status has updated.
*/
bool update(bool occupied);
/**
* Reset the parking timer and status.
*/
void reset();
///////////////////////////////
void connectDB();
/////////////////////////////
private:
/**
* Main entry of the timer thread
*/
void runTimer();
/**
* Start the parking timer
*/
void startTimer(int res_timeLimit, const std::string PN);
void startTimer();
/**
* Stop the parking timer, if any
*/
void stopTimer();
/**
* Notify a expiration message to the global message queue
*/
void notifyExpiration();
//-----------------------------------
// Static functions and variables
//-----------------------------------
public:
/**
* Set the shared message queue for server-side communication.
*/
static void setMessageQueue(std::shared_ptr<MessageQueue> &messageQueue);
/**
* Set the camera frame reader for the expiration event.
*/
static void setVideoReader(std::shared_ptr<SerialVideoReader> &videoReader);
/**
* Set the positive threshold
*/
static void setPositiveThreshold(int positiveThreshold);
/**
* Set the negative threshold
*/
static void setNegativeThreshold(int negativeThreshold);
private:
/**
* Network message queue for uploading the parking spot status information to the server.
* Data will be inserted when the status changes
*/
static std::shared_ptr<MessageQueue> mServerMsgQueue;
/**
* Since the parking enforcement is time-critical, each timer needs to acquire the camera
* frame at the time of an expiration event.
*/
static std::shared_ptr<SerialVideoReader> mVideoReader;
/**
* The positive threshold to be estimated as an occupied parking spot.
*/
static int mPositiveThreshold;
/**
* The negative threshold to be estimated as an unoccupied parking spot.
*/
static int mNegativeThreshold;
};
}