- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I'm trying out the blob tracking algorithm using the R200 RealSense, I followed the steps in the manual and looked at how the sample in the SDK uses the algorithm to get the blobs but I can't seem to get it right. I don't think I got my image right, does anyone have any suggestions? Or in that matter have an simple example using the blob tracking in c++ I could look at to get an idea of what I'm doing wrong. It's for a school project, I'm doing a system that could help the visually impaired detect objects with all Intel technology. Also I'm not a computer science mayor so sorry if my code is messy.
Thank you!
Sofía G.
#include <Windows.h> #include <iostream> #include <wchar.h> #include <stdio.h> #include <stdlib.h> #include "pxcsensemanager.h" #include "pxccapture.h" #include "pxcvideomodule.h" #include "utilities/pxcmaskutils.h" #include "pxcblobmodule.h" #include "pxcblobconfiguration.h" #include "pxcblobdata.h" #include "pxcsession.h" #include "pxccapture.h" #include "util_cmdline.h" #include "util_render.h" #include <conio.h> #define NFRAMES 500 int maxBlobToShow; int wmain(int argc, WCHAR* argv[]) { wprintf_s(L"Hello, World!\n"); PXCSenseManager *session = PXCSenseManager::CreateInstance(); if (!session) { wprintf_s(L"Unable to create the PXCSenseManager\n"); return 3; } wprintf_s(L"Creating Session\n"); //get capture manager instance if file record is set to true (m_brecord) PXCCaptureManager *captureManager = session->QueryCaptureManager(); //BLOB DATA CODE & CONFIGURATION session->EnableBlob(0); PXCBlobModule*blobModule = session->QueryBlob(); PXCBlobData*blobData=blobModule->CreateOutput(); maxBlobToShow = 4; int numOfBlobs = blobData->QueryNumberOfBlobs(); if (maxBlobToShow>numOfBlobs) { maxBlobToShow = numOfBlobs; } PXCBlobData::AccessOrderType accessOrder = PXCBlobData::ACCESS_ORDER_NEAR_TO_FAR; UtilRender renderc(L"Color"); UtilRender renderd(L"Depth"); pxcStatus status; PXCVideoModule::DataDesc streams = {}; if (captureManager->QueryCapture()) { captureManager->QueryCapture()->QueryDeviceInfo(0, &streams.deviceInfo); } else { streams.deviceInfo.streams = PXCCapture::STREAM_TYPE_COLOR | PXCCapture::STREAM_TYPE_DEPTH; streams.deviceInfo.streams = PXCCapture::STREAM_TYPE_DEPTH; } session->EnableStreams(&streams); //initialize pipeline status = session->Init(); if (status < PXC_STATUS_NO_ERROR) { wprintf_s(L"Failed to locate any video stream(s)\n"); session->Release(); return status; } wprintf_s(L"Streaming Data\n"); //stream data for (int nframes = 0; nframes < NFRAMES; nframes++) { //wait until new frame is availaible and locks it status = session->AcquireFrame(false); if (status < PXC_STATUS_NO_ERROR) { if (status == PXC_STATUS_STREAM_CONFIG_CHANGED) { wprintf_s(L"Stream Config changed. Reinitializing\n"); session->Close(); } break; } wprintf_s(L"Rendering Streams\n"); //Render streams const PXCCapture::Sample *sample = session->QuerySample(); if (sample) { if (sample->depth && !renderd.RenderFrame(sample->depth)) break; if (sample->color && !renderc.RenderFrame(sample->color)) break; } // BLOB EXTRACTION TO IMAGE pxcI32 iBlobsNum = blobData->QueryNumberOfBlobs(); for (int i = 0; i < iBlobsNum; i++) { PXCBlobData::IBlob * pBlob = NULL; //blobData->QueryBlob(); THIS LINE DOESN'T SEEM TO WORK, SHOULD I ADD THE PXCBLOBEXTRACTION?? // handle extracted blob data pxcI32 nContours = pBlob->QueryNumberOfContours(); } // IMAGE PROCESSING USING PIXEL DATA IN THE IMAGE TO FIND OBJECTS AND LOCATE THEM EITHER IN THE RIGHT,CENTER, OR LEFT POSITION OF THE IMAGE. STILL IN DEVELOPMENT IF YOU HAVE ANY SUGGESTIONS I WOULD APPRECIATE THEM //release frame session->ReleaseFrame(); wprintf_s(L"To quit press e\n"); //check for keystroke press if (_kbhit()) { int key = _getch() & 255; if (key == 27 || key == 'q' || key == 'Q') { break; } } if (nframes=499){ nframes = 0; } } while (status == PXC_STATUS_STREAM_CONFIG_CHANGED); wprintf_s(L"Exiting"); blobData->Release(); return 0; session->Release(); return 0; system("pause"); return 0; }
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Have you looked at our sample code @C:\Program Files (x86)\Intel\RSSDK\sample\DF_BlobViewer? What the image did you get? Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
David Lu (Intel) wrote:
Have you looked at our sample code @C:\Program Files (x86)\Intel\RSSDK\sample\DF_BlobViewer? What the image did you get? Thanks!
Yes I have tried the sample for the BlobViewer and I got the image attached: It works perfectly, I based my code on this and it didn't work. I talked to a colleague and he passed me his code to track the Blobs is using OpenCV to send out how many blobs it detects. I will include it so if anyone encounters the same problem as me. Also do you know how the BlobData is managed, in order to detect if a blob is in a particular area of the image?
Thank you so much!
Sofia G.
#include <Windows.h> #include "pxcsensemanager.h" #include "pxcblobmodule.h" #include "util_cmdline.h" #include "util_render.h" #include <conio.h> #include <inttypes.h> #include <iostream> #include <opencv2/opencv.hpp> using namespace std; using namespace cv; int maxBlobToShow; int main(int argc, char* argv[]) { wprintf_s(L"Prueba RealSense\n"); pxcStatus sts; PXCSenseManager *psm = 0; psm = PXCSenseManager::CreateInstance(); if (!psm) { wprintf_s(L"Unable to create the PXCSenseManager\n"); return 1; } wprintf_s(L"Creando Session\n"); //get capture manager instance if file record is set to true (m_brecord) PXCCaptureManager *captureManager = psm->QueryCaptureManager(); //BLOB DATA sts = psm->EnableBlob(0); if (sts < PXC_STATUS_NO_ERROR) { wprintf_s(L"Unable to enable Blob Analysis \n"); return 2; } PXCBlobModule*blobAnalyzer = psm->QueryBlob(); if (!psm) { return 3; } PXCVideoModule::DataDesc streams = {}; if (captureManager->QueryCapture()) { captureManager->QueryCapture()->QueryDeviceInfo(0, &streams.deviceInfo); } else { streams.deviceInfo.streams = PXCCapture::STREAM_TYPE_COLOR | PXCCapture::STREAM_TYPE_DEPTH; streams.deviceInfo.streams = PXCCapture::STREAM_TYPE_DEPTH; } psm->EnableStreams(&streams); //initialize pipeline sts = psm->Init(); if (sts < PXC_STATUS_NO_ERROR) { wprintf_s(L"Failed to locate any video stream(s)\n"); psm->Release(); return sts; } PXCBlobData*outputBlob = blobAnalyzer->CreateOutput(); PXCBlobConfiguration*configblob = blobAnalyzer->CreateActiveConfiguration(); configblob->SetMaxBlobs(pxcI32(4)); configblob->SetBlobSmoothing(pxcI32(0.4)); configblob->ApplyChanges(); PXCBlobData::AccessOrderType accessOrder = PXCBlobData::ACCESS_ORDER_NEAR_TO_FAR; UtilRender renderc(L"Color"); UtilRender renderd(L"Depth"); wprintf_s(L"Streaming Data\n"); wprintf_s(L"To quit press 'ESC' or 'Q'\n"); //stream data bool keepRunning = true; while (keepRunning) { outputBlob->Update(); //wait until new frame is availaible and locks it sts = psm->AcquireFrame(); // decia false if (sts < PXC_STATUS_NO_ERROR) { if (sts == PXC_STATUS_STREAM_CONFIG_CHANGED) { wprintf_s(L"Stream Config changed. Reinitializing\n"); psm->Close(); } break; } //Render streams const PXCCapture::Sample *sample = psm->QuerySample(); if (sample) { if (sample->depth && !renderd.RenderFrame(sample->depth)) break; if (sample->color && !renderc.RenderFrame(sample->color)) break; } // BLOB------------------------------ pxcI32 numOfBlobs = outputBlob->QueryNumberOfBlobs(); cout << numOfBlobs << endl; psm->ReleaseFrame(); //check for keystroke press if (_kbhit()) { int key = _getch() & 255; if (key == 27 || key == 'q' || key == 'Q') { break; } } } while (sts == PXC_STATUS_STREAM_CONFIG_CHANGED); wprintf_s(L"Exiting"); psm->Release(); return 0; }

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page