1+ #include " cus_cam.h"
2+ #include " infinite_sense.h"
3+ namespace infinite_sense {
4+
5+ CustomCam::~CustomCam () {
6+
7+ }
8+
9+ bool CustomCam::Initialization () {
10+ return true ;
11+ }
12+
13+ void CustomCam::Stop () {
14+ Disable ();
15+ std::this_thread::sleep_for (std::chrono::milliseconds{500 });
16+ for (auto &cam_thread : cam_threads_) {
17+ while (cam_thread.joinable ()) {
18+ cam_thread.join ();
19+ }
20+ }
21+ cam_threads_.clear ();
22+ cam_threads_.shrink_to_fit ();
23+ }
24+ void CustomCam::Receive (void *handle, const std::string &name) {
25+ while (is_running_) {
26+ // 这里的time_stamp_us是相机触发时间,需要加上曝光时间的一半,以获得相机拍摄的时间
27+ if (params_.find (name) == params_.end ()) {
28+ LOG (ERROR) << " cam " << name << " not found!" ;
29+ }
30+ else {
31+ if (uint64_t time; GET_LAST_TRIGGER_STATUS (params_[name], time)) {
32+ cam_data.time_stamp_us = time;
33+ }
34+ else {
35+ LOG (ERROR) << " cam " << name << " not found!" ;
36+ }
37+ }
38+
39+ cam_data.image = GMat (st_out_frame.stFrameInfo .nHeight , st_out_frame.stFrameInfo .nWidth ,
40+ GMatType<uint8_t , 1 >::Type, st_out_frame.pBufAddr );
41+
42+ messenger.PubStruct (name,&cam_data,sizeof (cam_data));
43+ std::this_thread::sleep_for (std::chrono::milliseconds{2 });
44+ }
45+ }
46+ void CustomCam::Start () {
47+ std::string name = " cam" ;
48+ cam_threads_.emplace_back (&CustomCam::Receive, this , nullptr , name);
49+ }
50+ } // namespace infinite_sense
0 commit comments