UsTK : Ultrasound ToolKit  version 2.0.1 under development (2024-11-21)
Tutorial: UsTK grabber tutorial for ultrasonix station with computation of confidence map of the image

Introduction

This tutorial expains how to apply a confidence map algorithm in real-time on frames grabbed from ultrasonix station.

Note that the source code used in this tutorial can be downloaded using the following command :

$ svn export https://github.com/lagadic/ustk.git/trunk/tutorial/ustk/ultrasonix

Apply the confidence map on pre-scan images

The following code shows how to apply a confidence map algorithm on a pre-scan image grabbed in real-time, and display the result.

The confidence map is produced using usScanlineConfidence2D class.

Note that the code runs in 2 separate threads :

  • The grabbing thread wich reads frames arriving on the network
  • The main thread wich computes the confidence map algorithm on each new frame, and displays the result.

You will need Qt and X11 to run the following code.

#include <iostream>
#include <visp3/ustk_core/usConfig.h>
#if (defined(USTK_HAVE_QT5) || defined(USTK_HAVE_VTK_QT)) && (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI))
#include <QApplication>
#include <QStringList>
#include <QtCore/QThread>
#include <visp3/ustk_grabber/usNetworkGrabberPreScan2D.h>
#include <visp3/ustk_confidence_map/usScanlineConfidence2D.h>
#include <visp3/gui/vpDisplayGDI.h>
#include <visp3/gui/vpDisplayX.h>
int main(int argc, char **argv)
{
// QT application
QApplication app(argc, argv);
qtGrabber->connectToServer();
// setting acquisition parameters
if (qApp->arguments().contains(QString("--probeID"))) {
header.probeId = qApp->arguments().at(qApp->arguments().indexOf(QString("--probeID")) + 1).toInt();
} else
header.probeId = 15; // 4DC7 id = 15 by default
if (qApp->arguments().contains(QString("--slotID"))) {
header.slotId = qApp->arguments().at(qApp->arguments().indexOf(QString("--slotID")) + 1).toInt();
} else
header.slotId = 0; // top slot id = 0 by default
if (qApp->arguments().contains(QString("--imagingMode"))) {
header.imagingMode = qApp->arguments().at(qApp->arguments().indexOf(QString("--imagingMode")) + 1).toInt();
} else
header.imagingMode = 0; // B-mode = 0 by default
// prepare image;
// Prepare display
#if defined(VISP_HAVE_X11)
vpDisplayX *display = NULL;
vpDisplayX *displayConf = NULL;
#elif defined(VISP_HAVE_GDI)
vpDisplayGDI *display = NULL;
vpDisplayGDI *displayConf = NULL;
#endif
bool displayInit = false;
// prepare confidence
usScanlineConfidence2D confidenceProcessor;
bool captureRunning = true;
// sending acquisition parameters
qtGrabber->initAcquisition(header);
qtGrabber->runAcquisition();
// our local grabbing loop
do {
grabbedFrame = qtGrabber->acquire();
confidenceProcessor.run(confidence, *grabbedFrame);
// local copy for vpDisplay
// localFrame = *grabbedFrame;
std::cout << "MAIN THREAD received frame No : " << grabbedFrame->getFrameCount() << std::endl;
std::cout << *grabbedFrame << std::endl;
// init display
if (!displayInit && grabbedFrame->getHeight() != 0 && grabbedFrame->getWidth() != 0) {
#if defined(VISP_HAVE_X11)
display = new vpDisplayX(*grabbedFrame);
displayConf = new vpDisplayX(confidence);
#elif defined(VISP_HAVE_GDI)
display = new vpDisplayGDI(*grabbedFrame);
displayConf = new vpDisplayGDI(confidence);
#endif
qtGrabber->useVpDisplay(display);
displayInit = true;
}
// processing display
if (displayInit) {
if (vpDisplay::getClick(*grabbedFrame, false))
captureRunning = false;
vpDisplay::display(*grabbedFrame);
vpDisplay::displayText(*grabbedFrame, 20, 20, std::string("Click to exit..."), vpColor::red);
vpDisplay::flush(*grabbedFrame);
vpDisplay::display(confidence);
vpDisplay::displayText(confidence, 20, 20, std::string("Click to exit..."), vpColor::red);
vpDisplay::flush(confidence);
// vpTime::wait(10); // wait to simulate a local process running on last frame frabbed
}
} while (captureRunning);
qtGrabber->stopAcquisition();
if (displayInit) {
delete display;
delete displayConf;
}
return 0;
}
#else
int main()
{
std::cout << "You should intall Qt5 (with wigdets and network modules), and display X to run this tutorial"
<< std::endl;
return 0;
}
#endif
Class to store additionnal informations arriving on the network with ultrasound images grabbed,...
quint32 getFrameCount() const
Specific class to grab pre-scan frames from the ultrasound station on the network.
usFrameGrabbedInfo< usImagePreScan2D< unsigned char > > * acquire()
void useVpDisplay(vpDisplay *display)
bool initAcquisition(const usNetworkGrabber::usInitHeaderSent &header)
Process a pre-scan image to determine the confidence map.
void run(usImagePreScan2D< unsigned char > &preScanConfidence, const usImagePreScan2D< unsigned char > &preScanImage)
VISP_EXPORT void display(const usOrientedPlane3D &plane, const vpImage< ImageDataType > &I, const vpHomogeneousMatrix &imageMworld, double Xscale=3000, double Yscale=3000, const vpColor &color=vpColor::green)
Display usOrientedPlane3D.

Next tutorial

You are now ready to see the next Tutorial: UsTK grabber tutorial to perform visual servoing on a 2D confidence map..