Camera: Orbbec Astra Stereo S
main.cpp file
include iostream>
include opencv2/opencv.hpp>
include opencv2/core/core.hpp>
include opencv2/highgui/highgui.hpp>
include opencv2/imgproc/imgproc.hpp>
include opencv2/videoio/videoio.hpp>
include opencv2/video.hpp>
include opencv2/videoio.hpp>
using namespace std;
using namespace cv;
int main()
{
cv::VideoCapture cam(CAP_OPENNI2);
Mat color, depth, depC;
while(true) { //Grab frames if ( ! cam.grab() ) std::cout << "grab() failed.\n"; if ( ! cam.retrieve( depth, CAP_OPENNI_DEPTH_MAP ) ) std::cout << "depth not retrieved.\n"; if ( ! cam.retrieve( color, CAP_OPENNI_BGR_IMAGE ) ) std::cout << "color not retrieved.\n";
std::cout << “Process depth → colormap\n”;
//Process depth → colormap
double min, max;
minMaxIdx(depth, &min, &max);
depth.convertTo(depth, CV_8UC1, 255./(max-min), -min);
applyColorMap(depth, depC, COLORMAP_HOT);
//Show imshow("Depth", depC); imshow("Color", color);
char c = waitKey(30); if (c == 'q') break; } return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.1)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
project(main)# project name
find_package(OpenCV REQUIRED)
if(OpenCV_FOUND)
message(STATUS “OpenCV FOUND”)
else()
message(STATUS “OpenCV NOT FOUND”)
endif()
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable(main main.cpp)
target_link_libraries(main ${OpenCV_LIBS})
OUTPUT
grab() failed.
depth not retrieved.
color not retrieved.
Process depth → colormap
terminate called after throwing an instance of ‘cv::Exception’
what(): OpenCV(4.2.0) /home/twentyface/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function ‘cvtColor’
Aborted (core dumped)