Now, i'm using real sense D435 camera.
I installed sdk 2.0 full package and upgraded camera version 5.1 to 5.9(latest version).
I want to code to get color image and depth image using visual studio 2015.
so i coded
#include <iostream>
#include "pxcsession.h"
#include "pxcprojection.h"
#include "pxcsensemanager.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <Windows.h>
#pragma comment(lib, "winmm.lib")
using namespace cv;
using namespace std;
class RealSenseAsenseManager
{
public:
~RealSenseAsenseManager()
{
if (senseManager != 0) {
senseManager->Release();
}
}
void initialize()
{
senseManager = PXCSenseManager::CreateInstance();
if (senseManager == nullptr) {
throw std::runtime_error("SenseManager failed");
}
pxcStatus sts = senseManager->EnableStream(
PXCCapture::StreamType::STREAM_TYPE_DEPTH,
DEPTH_WIDTH, DEPTH_HEIGHT, DEPTH_FPS);
if (sts < PXC_STATUS_NO_ERROR) {
throw std::runtime_error("Depth stream activation failed");
}
sts = senseManager->Init();
if (sts < PXC_STATUS_NO_ERROR) {
throw std::runtime_error("Pipeline Initialzation failed");
}
senseManager->QueryCaptureManager()->QueryDevice()->SetMirrorMode(
PXCCapture::Device::MirrorMode::MIRROR_MODE_HORIZONTAL);
}
void run()
{
while (1) {
updateFrame();
auto ret = showImage();
if (!ret) {
break;
}
}
}
private:
void updateFrame()
{
pxcStatus sts = senseManager->AcquireFrame(false);
if (sts < PXC_STATUS_NO_ERROR) {
return;
}
const PXCCapture::Sample *sample = senseManager->QuerySample();
if (sample) {
updateDepthImage(sample->depth);
}
senseManager->ReleaseFrame();
}
void updateDepthImage(PXCImage* depthFrame)
{
if (depthFrame == 0) {
return;
}
PXCImage::ImageData data;
pxcStatus sts = depthFrame->AcquireAccess(
PXCImage::Access::ACCESS_READ,
PXCImage::PixelFormat::PIXEL_FORMAT_RGB32, &data);
if (sts < PXC_STATUS_NO_ERROR) {
throw std::runtime_error("Taking Depth image failed");
}
PXCImage::ImageInfo info = depthFrame->QueryInfo();
depthImage = cv::Mat(info.height, info.width, CV_8UC4);
memcpy(depthImage.data, data.planes[0], data.pitches[0] * info.height);
depthFrame->ReleaseAccess(&data);
}
bool showImage()
{
if (depthImage.rows == 0 || (depthImage.cols == 0)) {
return true;
}
cv::imshow("Depth Image", depthImage);
int c = cv::waitKey(10);
if ((c == 27) || (c == 'q') || (c == 'Q')) {
// ESC|q|Q for Exit
return false;
}
return true;
}
private:
cv::Mat depthImage;
PXCSenseManager *senseManager = 0;
const int DEPTH_WIDTH = 640;
const int DEPTH_HEIGHT = 480;
const int DEPTH_FPS = 30.0f;
};
void main()
{
try {
RealSenseAsenseManager deep;
deep.initialize();
deep.run();
}
catch (std::exception& ex) {
std::cout << ex.what() << std::endl;
}
}
But this error appears.
sts = senseManager->Init();
if (sts < PXC_STATUS_NO_ERROR) {
throw std::runtime_error("Pipeline Initialzation failed");
}
Pipeline Initialization failed <-
I don't know how to solve this problem.
The depth camera connection is not likely to be wrong.
The color image is displayed. Only depth video is not available.
How I can solve this problem??
Thank you for reading my question.