36 #include <visp3/core/vpConfig.h>
39 #include <visp3/core/vpIoTools.h>
40 #include <visp3/core/vpMatrix.h>
41 #include <visp3/io/vpImageIo.h>
42 #include <visp3/io/vpParseArgv.h>
45 #include <visp3/ustk_core/us.h>
46 #include <visp3/ustk_core/usSequenceReader.h>
47 #include <visp3/ustk_needle_detection/usNeedleTrackerSIR2D.h>
51 std::string xml_filename;
52 double error_max = 4.;
55 if (xml_filename.empty()) {
57 if (!env_ipath.empty())
58 xml_filename = env_ipath +
"/needle/water_bath_minimal_noise_png/sequence.xml";
60 std::cout <<
"You should set USTK_DATASET_PATH environment var to access to ustk dataset" << std::endl;
80 vpMatrix controlPoints(2, 2);
83 controlPoints[0][0] = 197;
84 controlPoints[1][0] = 218;
85 controlPoints[0][1] = 211;
86 controlPoints[1][1] = 236;
87 needle.setControlPoints(controlPoints);
92 unsigned int nControlPoints = 2;
93 unsigned int nParticles = 200;
98 needleDetector.
init(I, nControlPoints, nParticles, needle);
99 std::cout <<
"Needle detector initialized." << std::endl;
103 vpColVector entryPose;
114 std::vector<vpColVector> tipGroundTruth;
118 tipGroundTruth.push_back(vec);
120 tipGroundTruth.push_back(vec);
123 tipGroundTruth.push_back(vec);
126 tipGroundTruth.push_back(vec);
129 tipGroundTruth.push_back(vec);
132 tipGroundTruth.push_back(vec);
135 tipGroundTruth.push_back(vec);
138 tipGroundTruth.push_back(vec);
141 tipGroundTruth.push_back(vec);
143 for (
int i = 0; i < 9; i++) {
145 needleDetector.
run(I, 0.0);
149 std::cout <<
"Tip position: (" << tipMean[0] <<
"," << tipMean[1] <<
")" << std::endl;
150 std::cout <<
"Needle length: " << needleDetector.
getNeedle()->
getLength() << std::endl;
151 std::cout <<
"Number of control points: " << needleDetector.
getNeedle()->
getOrder() + 1 << std::endl;
154 double error = sqrt(vpMath::sqr(tipMean[0] - tipGroundTruth.at(i)[0]) + vpMath::sqr(tipMean[1] - tipGroundTruth.at(i)[1]));
155 if (error > error_max) {
156 std::cout <<
"Error " << error <<
" exeeds " << error_max <<
" with i error=" << std::abs(tipMean[0] - tipGroundTruth.at(i)[0])
157 <<
", j error= " << std::abs(tipMean[1] - tipGroundTruth.at(i)[1]) << std::endl;
162 tipGroundTruth.clear();
164 std::cout <<
"Test succeed" << std::endl;
169 int main() { std::cout <<
"You should install xml2 to use this example" << std::endl; }
Needle detection in 2D images based on particle filtering.
usPolynomialCurve2D * getNeedle()
void init(unsigned int dims[2], unsigned int nPoints, unsigned int nParticles, const usPolynomialCurve2D &needle)
void run(vpImage< unsigned char > &I, double v)
double getLength(int nbCountSeg=50) const
vpMatrix getControlPoints() const
vpColVector getPoint(double parameter) const
unsigned int getOrder() const
Reading of sequences of ultrasound images.
void acquire(ImageType &image)
void setSequenceFileName(const std::string &sequenceFileName)
VISP_EXPORT std::string getDataSetPath()