Skip to content

Commit fa654ad

Browse files
authored
Clarify RealSense examples (SpectacularAI#41)
1 parent cb3b9e8 commit fa654ad

File tree

5 files changed

+69
-9
lines changed

5 files changed

+69
-9
lines changed

cpp/oak/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
You can find the non-commercial C++ SDK for OAK-D from https://github.com/SpectacularAI/sdk/releases.
44

5-
For commercial licenses and version for other OS and CPU arthicectures, contact us at https://www.spectacularai.com/#contact.
5+
For commercial licenses and version for other OS and CPU architectures, contact us at https://www.spectacularai.com/#contact.
66

77
## Linux
88

cpp/realsense/README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@
22

33
You can find the non-commercial C++ SDK for RealSense from https://github.com/SpectacularAI/sdk/releases.
44

5-
For commercial licenses and version for other OS and CPU arthicectures, contact us at https://www.spectacularai.com/#contact.
5+
For commercial licenses and version for other OS and CPU architectures, contact us at https://www.spectacularai.com/#contact.
66

77
## Linux
88

99
### Quick start
1010

11-
1. Unpack the SDK archive
12-
2. If you have not used the RealSense device before, run
11+
1. If you have not used the RealSense device before, run from the [librealsense GitHub repository](https://github.com/IntelRealSense/librealsense):
1312

14-
./bin/3rdparty/librealsense/setup_udev_rules.sh
13+
./scripts/setup_udev_rules.sh
1514

16-
3. Attach your RealSense D4XX or D3XX device to a USB3 port, using a USB3 cable
17-
4. Run the JSONL example:
15+
2. Attach your RealSense D4XX or D3XX device to a USB3 port, using a USB3 cable
16+
17+
3. Unpack the Spectacular AI SDK archive
18+
19+
4. In the extracted directory for your platform, run the pre-compiled example binary:
1820

1921
cd bin
2022
./vio_jsonl
@@ -61,7 +63,7 @@ For commercial licenses and version for other OS and CPU arthicectures, contact
6163

6264
### Using as a library
6365

64-
You must first install DepthAI. Todo this, you need to install following tools if you don't already have them:
66+
First install the following tools if you don't already have them:
6567
* Install Git for Windows https://git-scm.com
6668
* Install Visual Studio Community 2019 https://visualstudio.microsoft.com/vs/community/
6769
* When launching, install dependencies for "Desktop Development with C++"

cpp/realsense/helpers.hpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include <sys/stat.h>
2+
3+
#ifdef _MSC_VER
4+
#include <direct.h>
5+
#endif
6+
7+
int makeDir(const std::string &dir) {
8+
#ifdef _MSC_VER
9+
return _mkdir(dir.c_str());
10+
#else
11+
mode_t mode = 0755;
12+
return mkdir(dir.c_str(), mode);
13+
#endif
14+
}
15+
16+
bool folderExists(const std::string &folder) {
17+
#ifdef _MSC_VER
18+
struct _stat info;
19+
if (_stat(folder.c_str(), &info) != 0) return false;
20+
return (info.st_mode & _S_IFDIR) != 0;
21+
#else
22+
struct stat info;
23+
if (stat(folder.c_str(), &info) != 0) return false;
24+
return (info.st_mode & S_IFDIR) != 0;
25+
#endif
26+
}
27+
28+
bool createFolders(const std::string &folder) {
29+
int ret = makeDir(folder);
30+
if (ret == 0) return true;
31+
32+
switch (errno) {
33+
case ENOENT: {
34+
size_t pos = folder.find_last_of('/');
35+
if (pos == std::string::npos)
36+
#ifdef _MSC_VER
37+
pos = folder.find_last_of('\\');
38+
if (pos == std::string::npos)
39+
#endif
40+
return false;
41+
if (!createFolders(folder.substr(0, pos)))
42+
return false;
43+
return 0 == makeDir(folder);
44+
}
45+
case EEXIST:
46+
return folderExists(folder);
47+
48+
default:
49+
return false;
50+
}
51+
}

cpp/realsense/vio_mapper.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include <cstdlib>
1616
#include <set>
1717

18+
#include "helpers.hpp"
19+
1820
namespace {
1921
struct ImageToSave {
2022
std::string fileName;
@@ -50,6 +52,7 @@ std::function<void()> buildImageWriter(
5052
auto img = queue.front();
5153
queue.pop_front();
5254
lock.unlock();
55+
// If this line crashes, OpenCV probably has been built without PNG support.
5356
cv::imwrite(img.fileName.c_str(), img.mat);
5457
}
5558
};
@@ -98,6 +101,7 @@ int main(int argc, char** argv) {
98101
std::string recordingFolder;
99102
if (argc >= 2) {
100103
recordingFolder = argv[1];
104+
createFolders(recordingFolder);
101105
} else {
102106
std::cerr
103107
<< "Usage: " << argv[0] << " /path/to/recording/folder" << std::endl;

cpp/realsense/vio_mapper_legacy.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <atomic>
1414
#include <cstdlib>
1515

16+
#include "helpers.hpp"
17+
1618
namespace {
1719
struct ImageToSave {
1820
std::string fileName;
@@ -38,7 +40,7 @@ std::function<void()> buildImageWriter(
3840
auto img = queue.front();
3941
queue.pop_front();
4042
lock.unlock();
41-
43+
// If this line crashes, OpenCV probably has been built without PNG support.
4244
cv::imwrite(img.fileName.c_str(), img.mat);
4345
}
4446
};
@@ -51,6 +53,7 @@ int main(int argc, char** argv) {
5153
int keyFrameInterval = 10;
5254
if (argc >= 2) {
5355
recordingFolder = argv[1];
56+
createFolders(recordingFolder);
5457
if (argc >= 3) {
5558
keyFrameInterval = std::stoi(argv[2]);
5659
}

0 commit comments

Comments
 (0)