Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
cmake_minimum_required(VERSION 3.5)

project(CaptureDepthSource2DImage)

set(CMAKE_CXX_STANDARD 14)

set(Files ${PROJECT_SOURCE_DIR}/CaptureDepthSource2DImage.cpp)

if(CMAKE_HOST_WIN32)
find_package(MechEyeApi REQUIRED CONFIG PATHS "$ENV{MECHEYE_DIR}/API")
if(NOT MechEyeApi_FOUND)
message(
FATAL_ERROR "MechEyeApi not found. Please install MechEyeApi first.")
endif()
elseif(CMAKE_HOST_UNIX)
find_package(PkgConfig)
if(NOT PkgConfig_FOUND)
message(FATAL_ERROR "PkgConfig not found.")
else()
pkg_check_modules(MECHEYEAPI REQUIRED MechEyeApi)
if(NOT MECHEYEAPI_FOUND)
message(
FATAL_ERROR "MechEyeApi not found. Please install MechEyeApi first.")
endif()
endif()
endif()

# OpenCV_DIR: set as your OpenCV libraries directory; Uncomment next line to set
# OpenCV_DIR manually

# set(OpenCV_DIR "path to OpenCV directory")
find_package(OpenCV REQUIRED)
if(NOT OpenCV_FOUND)
message(
FATAL_ERROR
"OpenCV not found. Please point OpenCV_DIR to the directory of your OpenCV installation (containing the file OpenCVConfig.cmake)."
)
endif()

include_directories(${MECHEYEAPI_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS})
link_directories(${MECHEYEAPI_LIBRARY_DIRS} ${OpenCV_LIBRARY_DIRS})

add_executable(${PROJECT_NAME} ${Files})

target_link_libraries(${PROJECT_NAME} ${MECHEYEAPI_LIBRARIES} ${OpenCV_LIBS})
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*******************************************************************************
*BSD 3-Clause License
*
*Copyright (c) 2016-2025, Mech-Mind Robotics Technologies Co., Ltd.
*All rights reserved.
*
*Redistribution and use in source and binary forms, with or without
*modification, are permitted provided that the following conditions are met:
*
*1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
*2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
*3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
*THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
*AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
*IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
*DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
*FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
*DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
*SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
*CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
*OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
*OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
******************************************************************************/

/*
With this sample, you can obtain and save the 2D image from the depth source camera.
*/

#include <opencv2/opencv.hpp>
#include "area_scan_3d_camera/Camera.h"
#include "area_scan_3d_camera/api_util.h"

int main()
{
mmind::eye::Camera camera;
if (!findAndConnect(camera))
return -1;

mmind::eye::Frame2D frame2D;
auto errorStatus = camera.captureDepthSource2D(frame2D);
if (!errorStatus.isOK()) {
showError(errorStatus);
return -1;
}

cv::Mat image2D;
const std::string imageFile = "DepthSource2DImage.png";

switch (frame2D.colorType()) {
case mmind::eye::ColorTypeOf2DCamera::Monochrome:
{
mmind::eye::GrayScale2DImage grayImage = frame2D.getGrayScaleImage();
image2D = cv::Mat(grayImage.height(), grayImage.width(), CV_8UC1, grayImage.data());
break;
}
case mmind::eye::ColorTypeOf2DCamera::Color:
{
mmind::eye::Color2DImage colorImage = frame2D.getColorImage();
image2D = cv::Mat(colorImage.height(), colorImage.width(), CV_8UC3, colorImage.data());
break;
}
default:
std::cerr << "The depth source 2D image has an unsupported pixel type." << std::endl;
camera.disconnect();
return -1;
}

cv::imwrite(imageFile, image2D);
std::cout << "Capture and save the 2D image from the depth source camera: " << imageFile
<< std::endl;

camera.disconnect();
std::cout << "Disconnected from the camera successfully." << std::endl;
return 0;
}
120 changes: 120 additions & 0 deletions area_scan_3d_camera/Advanced/CaptureDepthSource2DImage/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# CaptureDepthSource2DImage Sample

With this sample, you can obtain and save the 2D image from the depth source camera.

> Note: This sample is only applicable to camera models with an external 2D camera, such as ULTRA M and NANO ULTRA models that provide a dedicated depth source 2D image.

If you have any questions or have anything to share, feel free to post on the [Mech-Mind Online Community](https://community.mech-mind.com/). The community also contains a [specific category for development with Mech-Eye SDK](https://community.mech-mind.com/c/mech-eye-sdk-development/19).

## Build the Sample

Prerequisites and instructions for building the sample on Windows and Ubuntu are provided.

### Windows

#### Prerequisites

The following software are required to build this sample. Please download and install these software.

* [Mech-Eye SDK (latest version)](https://downloads.mech-mind.com/?tab=tab-sdk)
* [Visual Studio (version 2017 or above)](https://visualstudio.microsoft.com/vs/community/)
* [CMake (version 3.2 or above)](https://cmake.org/download/)
* [OpenCV (version 3.4.5 or above)](https://opencv.org/releases/)

#### Instructions

1. Make sure that the sample is stored in a location with read and write permissions.
2. Add the following directories to the **Path** environment variable:

* `xxx/opencv/build/x64/vc14/bin`
* `xxx/opencv/build/x64/vc14/lib`

3. Run Cmake and set the source and build paths:

| Field | Path |
| :---- | :---- |
| Where is the source code | xxx/CaptureDepthSource2DImage |
| Where to build the binaries | xxx/CaptureDepthSource2DImage/build |

4. Click the **Configure** button. In the pop-up window, set the generator and platform according to the actual situation, and then click the **Finish** button.
5. When the log displays **Configuring done**, click the **Generate** button. When the log displays **Generating done**, click the **Open Project** button.
6. In Visual Studio toolbar, change the solution configuration from **Debug** to **Release**.
7. In the **Solution Explorer** panel, right-click the sample, and select **Set as Startup Project**.
8. Click the **Local Windows Debugger** button in the toolbar to run the sample.
9. Enter the index of the camera to which you want to connect, and press the Enter key. The obtained file is saved to the `build` folder.

### Ubuntu

Ubuntu 18 or above is required.

#### Prerequisites

* Update the software source list.

```bash
sudo apt-get update
```

* Install required tools.

```bash
sudo apt-get install -y build-essential pkg-config cmake
```

* Install [Mech-Eye SDK (latest version)](https://downloads.mech-mind.com/?tab=tab-sdk).

>Note: If you have installed Mech-Eye SDK before, please uninstall it first with the following command:
>
>```bash
>sudo dpkg -P MechEyeApi
>```

* If the system architecture is AMD64, execute the following command:

```bash
sudo dpkg -i 'Mech-Eye_API_x.x.x_amd64.deb'
```

* If the system architecture is ARM64, execute the following command:

```bash
sudo dpkg -i 'Mech-Eye_API_x.x.x_arm64.deb'
```

* Install third-party libraries: OpenCV is required.

* Install OpenCV (latest version):

```bash
sudo apt update && sudo apt install -y unzip
wget -O opencv.zip https://github.com/opencv/opencv/archive/4.x.zip
unzip opencv.zip
mkdir build && cd build
cmake ../opencv-4.x
cmake --build .
sudo make install
```

#### Instructions

1. Navigate to the directory of the sample.

```bash
cd xxx/area_scan_3d_camera/Advanced/CaptureDepthSource2DImage/
```

2. Configure and build the sample.

```bash
sudo mkdir build && cd build
sudo cmake ..
sudo make
```

3. Run the sample.

```bash
sudo ./CaptureDepthSource2DImage
```

4. Enter the index of the camera to which you want to connect, and press the Enter key. The obtained file is saved to `/CaptureDepthSource2DImage/build`.
5 changes: 5 additions & 0 deletions area_scan_3d_camera/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ endif()

option(USE_OPENCV "Enable samples which depend on OpenCV" ON)
option(USE_PCL "Enable samples which depend on Point Cloud Library (PCL)" ON)
if(CMAKE_HOST_WIN32)
add_definitions(-DNOMINMAX)
endif()
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64")
set(USE_HALCON FALSE)
add_compile_options(-mno-outline-atomics)
Expand All @@ -28,6 +31,7 @@ set(SAMPLES
Basic/CapturePointCloud
Basic/CapturePointCloudWithNormals
Basic/SaveVirtualDevice
Advanced/CaptureDepthSource2DImage
Advanced/CaptureStereo2DImages
Advanced/RenderDepthMap
Advanced/ConvertDepthMapToPointCloud
Expand Down Expand Up @@ -60,6 +64,7 @@ set(PCL_DEPENDING

set(OpenCV_DEPENDING
Capture2DImage
CaptureDepthSource2DImage
CaptureDepthMap
RenderDepthMap
CaptureStereo2DImages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ complete hand-eye calibration.
#include "area_scan_3d_camera/Camera.h"
#include "area_scan_3d_camera/api_util.h"
#include "HandEyeCalibrationUtil.h"
#include <iomanip>
#include <opencv2/highgui/highgui.hpp>

int main()
Expand Down Expand Up @@ -197,6 +198,19 @@ int main()
}
break;
}
case CommandType::GetCurrentImageFirstCorner:
{
mmind::eye::PointXYZ corner;
mmind::eye::ErrorStatus status =
calibration.extractCurrentImageFirstCorner(camera, corner);
showError(status);
if (status.isOK()) {
std::cout << "The first corner is: " << std::fixed << std::setprecision(3)
<< corner.x << ", " << corner.y << ", " << corner.z
<< std::endl;
}
break;
}
case CommandType::Unknown:
{
std::cout << "Error: Unknown command" << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@

#define PI 3.14159265
namespace {
enum class CommandType { AddPose, Calibrate, GetPatternImg, GetOriginImg, Unknown };
enum class CommandType {
AddPose,
Calibrate,
GetPatternImg,
GetOriginImg,
GetCurrentImageFirstCorner,
Unknown
};
// Obtain keyboard input.
std::string getInputCommand()
{
Expand Down Expand Up @@ -121,6 +128,7 @@ CommandType enterCommand()
std::cout << "T: obtain the 2D image with feature recognition result" << std::endl;
std::cout << "A: enter the current robot pose" << std::endl;
std::cout << "C: calculate extrinsic parameters" << std::endl;
std::cout << "F: obtain the first corner of current image" << std::endl;
const auto command = getInputCommand();
if (command == "P" || command == "p") {
return CommandType::GetOriginImg;
Expand All @@ -134,6 +142,9 @@ CommandType enterCommand()
if (command == "C" || command == "c") {
return CommandType::Calibrate;
}
if (command == "F" || command == "f") {
return CommandType::GetCurrentImageFirstCorner;
}
return CommandType::Unknown;
}

Expand Down
6 changes: 6 additions & 0 deletions area_scan_3d_camera/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ The sample marked with `(HALCON)` requires [HALCON](https://www.mvtec.com/downlo
Set multiple exposure times, and then obtain and save the point cloud.
* [CapturePointCloudWithNormals](https://github.com/MechMindRobotics/mecheye_cpp_samples/tree/master/area_scan_3d_camera/Basic/CapturePointCloudWithNormals)
Calculate normals and save the point cloud with normals.
* [SaveVirtualDevice](https://github.com/MechMindRobotics/mecheye_cpp_samples/tree/master/area_scan_3d_camera/Basic/SaveVirtualDevice) `(OpenCV)`
Save the data acquired by the camera as a virtual device file.
* **Advanced**
* [CaptureDepthSource2DImage](https://github.com/MechMindRobotics/mecheye_cpp_samples/tree/master/area_scan_3d_camera/Advanced/CaptureDepthSource2DImage) `(OpenCV)`
Obtain and save the 2D image from the depth source camera.
* [ConvertDepthMapToPointCloud](https://github.com/MechMindRobotics/mecheye_cpp_samples/tree/master/area_scan_3d_camera/Advanced/ConvertDepthMapToPointCloud)
Generate a point cloud from the depth map and save the point cloud.
* [MultipleCamerasCaptureSequentially](https://github.com/MechMindRobotics/mecheye_cpp_samples/tree/master/area_scan_3d_camera/Advanced/MultipleCamerasCaptureSequentially) `(OpenCV)`
Expand All @@ -43,6 +47,8 @@ The sample marked with `(HALCON)` requires [HALCON](https://www.mvtec.com/downlo
Obtain and save 2D images, depth maps, and point clouds simultaneously from multiple cameras.
* [CapturePeriodically](https://github.com/MechMindRobotics/mecheye_cpp_samples/tree/master/area_scan_3d_camera/Advanced/CapturePeriodically) `(OpenCV)`
Obtain and save 2D images, depth maps, and point clouds periodically for the specified duration from a camera.
* [WarmUp](https://github.com/MechMindRobotics/mecheye_cpp_samples/tree/master/area_scan_3d_camera/Advanced/WarmUp) `(OpenCV)`
Warm up the device.
* [Mapping2DImageToDepthMap](https://github.com/MechMindRobotics/mecheye_cpp_samples/tree/master/area_scan_3d_camera/Advanced/Mapping2DImageToDepthMap)
Generate untextured and textured point clouds from a masked 2D image and a depth map.
* [RenderDepthMap](https://github.com/MechMindRobotics/mecheye_cpp_samples/tree/master/area_scan_3d_camera/Advanced/RenderDepthMap) `(OpenCV)`
Expand Down
Loading