Skip to content

Commit 41efdd2

Browse files
committed
Customize the camera type
1 parent bd51054 commit 41efdd2

5 files changed

Lines changed: 53 additions & 31 deletions

File tree

example/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
cmake_minimum_required(VERSION 3.10)
22
project(example)
33

4-
add_subdirectory(GigeCam)
4+
add_subdirectory(GigeCam)
5+
add_subdirectory(CustomCam)

example/CustomCam/CMakeLists.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
3+
project(custom_cam VERSION 1.0)
4+
5+
set(CMAKE_CXX_STANDARD 17)
6+
7+
if (NOT CMAKE_BUILD_TYPE)
8+
set(CMAKE_BUILD_TYPE Release)
9+
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -O3 -Wall")
10+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -Wall")
11+
endif ()
12+
13+
14+
add_executable(${PROJECT_NAME}
15+
main.cpp
16+
cus_cam.cpp
17+
cus_cam.h
18+
)
19+
target_link_directories(${PROJECT_NAME} PRIVATE
20+
# Add the path to the your cam SDK here
21+
)
22+
23+
target_link_libraries(${PROJECT_NAME} PRIVATE
24+
infinite_sense_core
25+
# Add the name of your cam SDK library here
26+
)
27+
28+
target_include_directories(${PROJECT_NAME} PRIVATE
29+
# Add the path to the your cam SDK header files here
30+
)
31+
set_target_properties(${PROJECT_NAME} PROPERTIES
32+
INSTALL_RPATH "$ORIGIN"
33+
)

example/CustomCam/cus_cam.cpp

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,30 @@ bool CustomCam::Initialization() {
1313
void CustomCam::Stop() {
1414
Disable();
1515
std::this_thread::sleep_for(std::chrono::milliseconds{500});
16-
for (auto &cam_thread : cam_threads_) {
16+
for (auto &cam_thread : cam_threads) {
1717
while (cam_thread.joinable()) {
1818
cam_thread.join();
1919
}
2020
}
21-
cam_threads_.clear();
22-
cam_threads_.shrink_to_fit();
21+
cam_threads.clear();
22+
cam_threads.shrink_to_fit();
2323
}
2424
void CustomCam::Receive(void *handle, const std::string &name) {
25-
while (is_running_) {
25+
Messenger &messenger = Messenger::GetInstance();
26+
while (is_running) {
2627
CamData cam_data;
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)) {
28+
if (params.find(name) != params.end()) {
29+
if (uint64_t time; GET_LAST_TRIGGER_STATUS(params[name], time)) {
3230
cam_data.time_stamp_us = time;
3331
}
34-
else {
35-
LOG(ERROR) << "cam " << name << " not found!";
36-
}
3732
}
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-
33+
cam_data.image = GMat();
4234
messenger.PubStruct(name,&cam_data,sizeof(cam_data));
43-
std::this_thread::sleep_for(std::chrono::milliseconds{2});
35+
std::this_thread::sleep_for(std::chrono::milliseconds{1});
4436
}
4537
}
4638
void CustomCam::Start() {
4739
std::string name = "cus_camera";
48-
cam_threads_.emplace_back(&CustomCam::Receive, this, nullptr, name);
40+
cam_threads.emplace_back(&CustomCam::Receive, this, nullptr, name);
4941
}
5042
} // namespace infinite_sense

example/CustomCam/cus_cam.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@
33
namespace infinite_sense {
44
class CustomCam final : public Sensor {
55
public:
6-
explicit CustomCam(const std::map<std::string, TriggerDevice>& params) : params_(params) {}
76
~CustomCam() override;
8-
9-
CustomCam(const CustomCam&) = delete;
10-
CustomCam& operator=(const CustomCam&) = delete;
11-
127
bool Initialization() override;
138
void Stop() override;
149
void Start() override;

example/CustomCam/main.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@
22
#include "cus_cam.h"
33
using namespace infinite_sense;
44
int main() {
5-
65
// 1.创建同步器
76
Synchronizer synchronizer;
8-
97
synchronizer.SetUsbLink("/dev/ttyACM0", 460800);
108
// 2.配置同步接口
11-
std::map<std::string, TriggerDevice> params;
12-
params["cus_camera"] = CAM_1;
13-
const auto cus_cam = std::make_shared<CustomCam>(params);
14-
synchronizer.UseCam(cus_cam);
9+
std::map<std::string, TriggerDevice> params = {
10+
{"camera_1", CAM_1},
11+
{"camera_2", CAM_2},
12+
};
13+
auto mv_cam = std::make_shared<CustomCam>();
14+
mv_cam->SetParams(params);
15+
synchronizer.UseCam(mv_cam);
1516

1617
// 3.开启同步
1718
synchronizer.Start();
1819

19-
// 4.订阅数据
20+
// 4.接受数据
2021
Synchronizer::PrintSummary();
2122
zmq::context_t context(1);
2223
zmq::socket_t subscriber(context, zmq::socket_type::sub);

0 commit comments

Comments
 (0)