int main(int argc, char **argv) { InitVars(argc, argv, "../heh.cfg"); // Read image ImageRGB<byte> imagergb; ImageF image; ReadImage(argv[1], imagergb); ImageCopy(imagergb, image); // Run segmentation MatI seg(image.GetHeight(), image.GetWidth()); if (argc >= 3) { ReadMatrix(argv[2], seg); } else { FHSegmenter segmenter(image.GetWidth(), image.GetHeight()); segmenter.Compute(image, seg, 1, 50, 150); } //DREPORT(seg); // Compute features HehFeatureGen gen; gen.Compute(imagergb, image, seg); for (int i = 0; i < gen.features.size(); i++) { DREPORT(i); SCOPED_INDENT; const HehFeature& f = gen.features[i]; DLOG << f; } return 0; }
static inline void innerColMultiply( const BlockT* blocks, const IndexT &index, const typename IndexT::Index outerIdx, const RhsT& rhs, ResT& res, ScalarT alpha ) { typedef Segmenter< BlockDims< BlockT, Transpose >::Rows, ResT, typename IndexT::Index > ResSegmenter ; ResSegmenter segmenter( res, index.innerOffsetsData() ) ; for( typename IndexT::InnerIterator it( index, outerIdx ) ; it ; ++ it ) { typename ResSegmenter::ReturnType res_seg(segmenter[ it.inner() ] ) ; mv_add< Transpose >( blocks[ it.ptr() ], rhs, res_seg, alpha ) ; } }
int main( int argc, const char* argv[]) { if (argc <= 1 || std::strcmp( argv[1], "-h") == 0 || std::strcmp( argv[1], "--help") == 0) { printUsage( argc, argv); return 0; } else if (argc < 2) { std::cerr << "ERROR too few parameters" << std::endl; printUsage( argc, argv); return 1; } else if (argc > 2) { std::cerr << "ERROR too many parameters" << std::endl; printUsage( argc, argv); return 1; } try { g_errorhnd = strus::createErrorBuffer_standard( 0, 2); if (!g_errorhnd) { throw std::runtime_error("failed to create error buffer object"); } char rulefile[ 256]; snprintf( rulefile, sizeof(rulefile), "%s%c%s", argv[1], strus::dirSeparator(), "rules.txt"); char inputfile[ 256]; snprintf( inputfile, sizeof(inputfile), "%s%c%s", argv[1], strus::dirSeparator(), "input.tsv"); char expectedfile[ 256]; snprintf( expectedfile, sizeof(expectedfile), "%s%c%s", argv[1], strus::dirSeparator(), "expected.txt"); char outputfile[ 256]; snprintf( outputfile, sizeof(outputfile), "%s%c%s", argv[1], strus::dirSeparator(), "output.txt"); std::auto_ptr<strus::SegmenterInterface> segmenter( strus::createSegmenter_tsv( g_errorhnd)); if (!segmenter.get()) throw std::runtime_error("failed to create segmenter"); std::auto_ptr<strus::SegmenterInstanceInterface> segmenterInstance( segmenter->createInstance()); if (!segmenterInstance.get()) throw std::runtime_error("failed to create segmenter instance"); strus::analyzer::DocumentClass dclass( segmenter->mimeType(), "UTF-8"); std::string rulesrc; unsigned int ec = strus::readFile( rulefile, rulesrc); if (ec) throw std::runtime_error( std::string("error reading rule file ") + rulefile + ": " + ::strerror(ec)); std::vector<RuleDescription> rulear = parseRuleDescriptions( rulesrc); std::vector<RuleDescription>::const_iterator ri = rulear.begin(), re = rulear.end(); for (; ri != re; ++ri) { if (ri->endIdx) { segmenterInstance->defineSubSection( ri->startIdx, ri->endIdx, ri->expression); #ifdef STRUS_LOWLEVEL_DEBUG std::cout << "SECTION " << ri->startIdx << ":" << ri->endIdx << " " << ri->expression << std::endl; #endif } else { segmenterInstance->defineSelectorExpression( ri->startIdx, ri->expression); #ifdef STRUS_LOWLEVEL_DEBUG std::cout << "MATCH " << ri->startIdx << " " << ri->expression << std::endl; #endif } } std::auto_ptr<strus::SegmenterContextInterface> segmenterContext( segmenterInstance->createContext( dclass)); if (!segmenterContext.get()) throw std::runtime_error("failed to create segmenter context"); std::string inputsrc; ec = strus::readFile( inputfile, inputsrc); if (ec) throw std::runtime_error( std::string("error reading input file ") + inputfile + ": " + ::strerror(ec)); #ifdef STRUS_LOWLEVEL_DEBUG std::cout << "INPUT" << std::endl << inputsrc << std::endl; #endif std::size_t chunksize = 100; std::size_t chunkpos = 0; for (; chunkpos + chunksize < inputsrc.size(); chunkpos += chunksize) { segmenterContext->putInput( inputsrc.c_str() + chunkpos, chunksize, false); #ifdef STRUS_LOWLEVEL_DEBUG std::cout << "PUT INPUT" << std::endl << std::string( inputsrc.c_str() + chunkpos, chunksize) << std::endl; #endif } chunksize = inputsrc.size() - chunkpos; segmenterContext->putInput( inputsrc.c_str() + chunkpos, chunksize, true); #ifdef STRUS_LOWLEVEL_DEBUG std::cout << "PUT INPUT" << std::endl << std::string( inputsrc.c_str() + chunkpos, chunksize) << std::endl; #endif int id = 0; strus::SegmenterPosition pos; const char* segment; std::size_t segmentsize; std::ostringstream out; while (segmenterContext->getNext( id, pos, segment, segmentsize)) { out << "[" << id << "] " << std::string(segment,segmentsize) << std::endl; } std::cout << out.str(); if (g_errorhnd->hasError()) { throw std::runtime_error( g_errorhnd->fetchError()); } ec = strus::writeFile( outputfile, out.str()); if (ec) throw std::runtime_error( std::string("error writing output file ") + outputfile + ": " + ::strerror(ec)); std::string expectedsrc; ec = strus::readFile( expectedfile, expectedsrc); if (ec) throw std::runtime_error( std::string("error reading expected file ") + expectedfile + ": " + ::strerror(ec)); if (out.str() != expectedsrc) { throw std::runtime_error("output not as expected"); } std::cerr << "OK" << std::endl; delete g_errorhnd; return 0; } catch (const std::bad_alloc&) { std::cerr << "ERROR memory allocation error" << std::endl; } catch (const std::runtime_error& e) { std::cerr << "ERROR " << e.what() << std::endl; } catch (const std::exception& e) { std::cerr << "EXCEPTION " << e.what() << std::endl; } if (g_errorhnd) { delete g_errorhnd; } return -1; }
int main( int argc, const char* argv[]) { if (argc <= 1 || std::strcmp( argv[1], "-h") == 0 || std::strcmp( argv[1], "--help") == 0) { printUsage( argc, argv); return 0; } else if (argc < 5) { std::cerr << "ERROR too few parameters" << std::endl; printUsage( argc, argv); return 1; } else if (argc > 5) { std::cerr << "ERROR too many parameters" << std::endl; printUsage( argc, argv); return 1; } try { g_errorhnd = strus::createErrorBuffer_standard( 0, 2); if (!g_errorhnd) { throw std::runtime_error("failed to create error buffer object"); } std::string inpfile( argv[1]); std::string tagfile( argv[2]); std::string outfile( argv[3]); std::string expfile( argv[4]); std::auto_ptr<strus::SegmenterInterface> segmenter( strus::createSegmenter_textwolf( g_errorhnd)); if (!segmenter.get()) throw std::runtime_error("failed to create segmenter"); std::auto_ptr<strus::SegmenterInstanceInterface> segmenterInstance( segmenter->createInstance()); if (!segmenterInstance.get()) throw std::runtime_error("failed to create segmenter instance"); std::string tagsrc; unsigned int ec; ec = strus::readFile( tagfile, tagsrc); if (ec) throw std::runtime_error( std::string("error reading markup file ") + tagfile + ": " + ::strerror(ec)); std::vector<MarkupDescription> markups = parseMarkupDescriptions( tagsrc); std::string inpsrc; ec = strus::readFile( inpfile, inpsrc); if (ec) throw std::runtime_error( std::string("error reading markup file ") + inpfile + ": " + ::strerror(ec)); std::auto_ptr<strus::DocumentClassDetectorInterface> detector( strus::createDetector_std( g_errorhnd)); if (!detector.get()) throw std::runtime_error("failed to create document class detector"); strus::analyzer::DocumentClass dclass; if (!detector->detect( dclass, inpsrc.c_str(), inpsrc.size())) throw std::runtime_error("failed to detect document class of input source"); std::ostringstream outstr; std::auto_ptr<strus::SegmenterMarkupContextInterface> segmenterMarkupContext( segmenterInstance->createMarkupContext( dclass, inpsrc)); if (!segmenterMarkupContext.get()) throw std::runtime_error("failed to create markup segmenter context"); strus::SegmenterPosition segpos = 0; const char* segment; std::size_t segmentsize; outstr << "Input document:" << std::endl; while (segmenterMarkupContext->getNext( segpos, segment, segmentsize)) { outstr << segpos << ": " << segmenterMarkupContext->tagName( segpos) << " " << segmenterMarkupContext->tagLevel( segpos) << std::endl; } std::vector<MarkupDescription>::const_iterator mi = markups.begin(), me = markups.end(); for (; mi != me; ++mi) { #ifdef STRUS_LOWLEVEL_DEBUG std::cout << "MARKUP " << mi->position << ": " << mi->type << " " << mi->name << "'" << mi->value << "'" << std::endl; #endif if (mi->type == '>') { segmenterMarkupContext->putOpenTag( mi->position, mi->offset, mi->name); } else if (mi->type == '<') { segmenterMarkupContext->putCloseTag( mi->position, mi->offset, mi->name); } else if (mi->type == '@') { segmenterMarkupContext->putAttribute( mi->position, mi->offset, mi->name, mi->value); } else { throw std::runtime_error("unknown type in markup description"); } } outstr << std::endl << "Output document:" << std::endl; outstr << segmenterMarkupContext->getContent() << std::endl; if (g_errorhnd->hasError()) { throw std::runtime_error( g_errorhnd->fetchError()); } std::cout << outstr.str(); ec = strus::writeFile( outfile, outstr.str()); if (ec) throw std::runtime_error( std::string("error writing output file ") + outfile + ": " + ::strerror(ec)); std::string expsrc; ec = strus::readFile( expfile, expsrc); if (ec) throw std::runtime_error( std::string("error reading expected file ") + expfile + ": " + ::strerror(ec)); if (outstr.str() != expsrc) { throw std::runtime_error("output not as expected"); } std::cerr << "OK" << std::endl; delete g_errorhnd; return 0; } catch (const std::bad_alloc&) { std::ostringstream msg; if (g_errorhnd->hasError()) { msg << "(" << g_errorhnd->fetchError() << ")"; } std::cerr << "ERROR memory allocation error" << msg.str() << std::endl; } catch (const std::runtime_error& e) { std::ostringstream msg; if (g_errorhnd->hasError()) { msg << "(" << g_errorhnd->fetchError() << ")"; } std::cerr << "ERROR " << e.what() << msg.str() << std::endl; } catch (const std::exception& e) { std::ostringstream msg; if (g_errorhnd->hasError()) { msg << "(" << g_errorhnd->fetchError() << ")"; } std::cerr << "EXCEPTION " << e.what() << msg.str() << std::endl; } if (g_errorhnd) { delete g_errorhnd; } return -1; }
int main(const int argc, const char **argv) { // instantiate a model manager: ModelManager manager("Frame Grabber Tester"); // Instantiate our various ModelComponents: nub::soft_ref<FrameGrabberConfigurator> gbc(new FrameGrabberConfigurator(manager)); manager.addSubComponent(gbc); nub::soft_ref<CameraControl> camera(new CameraControl(manager, "Camera Controller", "CameraControl", 0, true, 0, 1, 1)); manager.addSubComponent(camera); // Parse command-line: if (manager.parseCommandLine(argc, argv, "", 0, 0) == false) return(1); // do post-command-line configs: nub::soft_ref<FrameIstream> gb = gbc->getFrameGrabber(); if (gb.isInvalid()) LFATAL("You need to select a frame grabber type via the " "--fg-type=XX command-line option for this program " "to be useful"); int width = gb->getWidth(), height = gb->getHeight(); float delay = 0; // let's get all our ModelComponent instances started: manager.start(); XWindow wini(Dims(width, height), 0, 0, "test-input window"); XWindow wino1(Dims(width/4, height/4), 0, 0, "test-output window 1"); XWindow wino2(Dims(width/4, height/4), 0, 0, "test-output window 2"); XWindow winAux1(Dims(100, 450), 0, 0, "HSV levels 1"); XWindow winAux2(Dims(100, 450), 0, 0, "HSV levels 2"); Timer tim; Image< PixRGB<byte> > ima; Image< PixRGB<float> > fima; Image< PixRGB<byte> > display; Timer camPause; // to pause the move command camPause.reset(); uint64 t[NAVG]; int frame = 0; segmentImageMerge segmenter(2); // set up tracking parameters //segmenter.setTrackColor(10,10,0.15,0.20,150,150,0,true,15); segmenter.setTrackColor(13,7,0.17,0.3,156,30,0,true,15); //segmenter.setTrackColor(10,10,0.15,0.20,150,150,1,false,15); segmenter.setTrackColor(270,10,0.18,0.25,60,60,1,true,15); segmenter.setAdaptBound(20,5,.30,.15,170,100,0); //segmenter.setAdaptBound(15,5,.30,.25,140,100,0); segmenter.setAdaptBound(285,265,.25,.15,80,40,1); segmenter.setFrame(0,0,width/4,height/4,width/4,height/4,0); segmenter.setFrame(0,0,width/4,height/4,width/4,height/4,1); segmenter.setCircleColor(0,255,0,0); segmenter.setCircleColor(0,0,255,1); segmenter.setBoxColor(255,255,0,0); segmenter.setBoxColor(255,0,255,1); segmenter.setAdapt(3,true,3,true,3,true,0); segmenter.setAdapt(3,true,3,true,3,true,1); while(1) { tim.reset(); ima = gb->readRGB(); uint64 t0 = tim.get(); // to measure display time Image<PixRGB<byte> > Aux1; Image<PixRGB<byte> > Aux2; Aux1.resize(100,450,true); Aux2.resize(100,450,true); Image<byte> outputI1; Image<byte> outputI2; display = ima; segmenter.trackImage(ima,&display,0,&Aux1); segmenter.trackImage(ima,&display,1,&Aux2); segmenter.mergeImages(&display); if(camPause.get() > delay) { int modi,modj; segmenter.getImageTrackXY(&modi,&modj,0); //segmenter.getImageTrackXYMerge(&modi,&modj); modi = modi*8; modj = 480-modj*8; if(modi > 0 && modi < 640 && modj > 0 && modj < 480) { if(segmenter.returnLOT(0) == false) { camPause.reset(); delay = camera->moveCamXYFrame(modi,modj); } } } Image<byte> temp1 = segmenter.returnCandidateImage(0); Image<byte> temp2 = segmenter.returnCandidateImage(1); wini.drawImage(display); //wino1.drawImage(outputI1); wino1.drawImage(temp1); wino2.drawImage(temp2); winAux1.drawImage(Aux1); winAux2.drawImage(Aux2); t[frame % NAVG] = tim.get(); t0 = t[frame % NAVG] - t0; if (t0 > 28) LINFO("Display took %llums", t0); // compute and show framerate over the last NAVG frames: if (frame % NAVG == 0 && frame > 0) { uint64 avg = 0; for (int i = 0; i < NAVG; i ++) avg += t[i]; float avg2 = 1000.0 / (float)avg * NAVG; printf("Framerate: %.1f fps\n", avg2); } frame ++; } manager.stop(); return 0; }
void TesseractOcr::segment(PipelineData* pipeline_data) { CharacterSegmenter segmenter(pipeline_data); segmenter.segment(); }
/* Main tracking function - gets called by MT_TrackerFrameBase every * time step when the application is not paused. */ void DanceTracker::doTracking(IplImage* frame) { /* time-keeping, if necessary * NOTE this is not necessary for keeping track of frame rate */ static double t_prev = MT_getTimeSec(); double t_now = MT_getTimeSec(); m_dDt = t_now - t_prev; t_prev = t_now; /* keeping track of the frame number, if necessary */ m_iFrameCounter++; /* This checks every time step to see if the UKF parameters have changed and modifies the UKF structures accordingly. This will also get called the first time through b/c the "Prev" values get set to zero initially. There may be a more efficient way to do this, but because the values need to be embedded into the CvMat objects I'm not sure how else to do it. */ if( m_dSigmaPosition != m_dPrevSigmaPosition || m_dSigmaSpeed != m_dPrevSigmaSpeed || m_dSigmaPositionMeas != m_dPrevSigmaPositionMeas ) { /* these are the diagonal entries of the "Q" matrix, which represents the variances of the process noise. They're modeled here as being independent and uncorrellated. */ cvSetReal2D(m_pQ, 0, 0, m_dSigmaPosition*m_dSigmaPosition); cvSetReal2D(m_pQ, 1, 1, m_dSigmaPosition*m_dSigmaPosition); cvSetReal2D(m_pQ, 2, 2, m_dSigmaHeading*m_dSigmaSpeed); cvSetReal2D(m_pQ, 3, 3, m_dSigmaSpeed*m_dSigmaSpeed); /* these are the diagonal entries of the "R matrix, also assumed to be uncorrellated. */ cvSetReal2D(m_pR, 0, 0, m_dSigmaPositionMeas*m_dSigmaPositionMeas); cvSetReal2D(m_pR, 1, 1, m_dSigmaPositionMeas*m_dSigmaPositionMeas); /* this step actually copies the Q and R matrices to the UKF and makes sure that it's internals are properly initialized - it's set up to handle the fact that the sizes of these matrices could have changed. */ for(unsigned int i = 0; i < m_iNObj; i++) { MT_UKFCopyQR(m_vpUKF[i], m_pQ, m_pR); } } HSVSplit(frame); cvThreshold(m_pHFrame, m_pThreshFrame, m_iHThresh_Low, 255, CV_THRESH_BINARY); cvThreshold(m_pHFrame, m_pTempFrame1, m_iHThresh_High, 255, CV_THRESH_BINARY_INV); cvAnd(m_pThreshFrame, m_pTempFrame1, m_pThreshFrame); cvThreshold(m_pSFrame, m_pTempFrame1, m_iSThresh_Low, 255, CV_THRESH_BINARY); cvThreshold(m_pSFrame, m_pTempFrame2, m_iSThresh_High, 255, CV_THRESH_BINARY_INV); cvAnd(m_pTempFrame1, m_pTempFrame2, m_pTempFrame1); cvAnd(m_pThreshFrame, m_pTempFrame1, m_pThreshFrame); cvThreshold(m_pVFrame, m_pTempFrame1, m_iVThresh_Low, 255, CV_THRESH_BINARY); cvThreshold(m_pVFrame, m_pTempFrame2, m_iVThresh_High, 255, CV_THRESH_BINARY_INV); cvAnd(m_pTempFrame1, m_pTempFrame2, m_pTempFrame1); cvAnd(m_pThreshFrame, m_pTempFrame1, m_pTempFrame1); cvSub(BG_frame, m_pVFrame, m_pTempFrame2); cvThreshold(m_pTempFrame2, m_pTempFrame2, m_iBGThresh, 255, CV_THRESH_BINARY); cvOr(m_pTempFrame1, m_pTempFrame2, m_pThreshFrame); cvSmooth(m_pThreshFrame, m_pThreshFrame, CV_MEDIAN, 3); if(ROI_frame) { cvAnd(m_pThreshFrame, ROI_frame, m_pThreshFrame); } /* std::vector<YABlob> yblobs = m_YABlobber.FindBlobs(m_pThreshFrame, 5, m_iBlobAreaThreshLow, NO_MAX, m_iBlobAreaThreshHigh); int ny = yblobs.size(); m_vdBlobs_X.resize(ny); m_vdBlobs_Y.resize(ny); m_vdBlobs_Orientation.resize(ny); for(unsigned int i = 0; i < yblobs.size(); i++) { m_vdBlobs_X[i] = yblobs[i].COMx; m_vdBlobs_Y[i] = yblobs[i].COMy; m_vdBlobs_Orientation[i] = 0; }*/ m_vbNoMeasurement.assign(m_iNObj, false); Dance_Segmenter segmenter(this); segmenter.setDebugFile(stdout); segmenter.m_iMinBlobPerimeter = 1; segmenter.m_iMinBlobArea = m_iBlobAreaThreshLow; segmenter.m_iMaxBlobArea = m_iBlobAreaThreshHigh; segmenter.m_dOverlapFactor = m_dOverlapFactor; if(m_iFrameCounter <= 1) { std::ifstream in_file; in_file.open("initials.dat"); double x, y; m_vBlobs.resize(0); m_vBlobs = MT_readDSGYABlobsFromFile("initials.dat"); m_vInitBlobs.resize(0); m_viAssignments.resize(0); /* m_vBlobs = segmenter.segmentFirstFrame(m_pThreshFrame, m_iNObj); */ } else { MT_writeDSGYABlobsToFile(m_vBlobs, "blobs-in.dat"); MT_writeDSGYABlobsToFile(m_vPredictedBlobs, "predicted-in.dat"); bool use_prediction = true; m_vBlobs = segmenter.doSegmentation(m_pThreshFrame, use_prediction ? m_vPredictedBlobs : m_vBlobs); m_viAssignments = segmenter.getAssignmentVector(&m_iAssignmentRows, &m_iAssignmentCols); m_vInitBlobs = segmenter.getInitialBlobs(); } /* prediction is done below - this makes sure the predicted blobs are OK no matter what */ m_vPredictedBlobs = m_vBlobs; unsigned int sc = 0; bool same_frame = false; for(unsigned int i = 0; i < m_vBlobs.size(); i++) { if(m_vdBlobs_X[i] == m_vBlobs[i].m_dXCenter) { sc++; } m_vdBlobs_X[i] = m_vBlobs[i].m_dXCenter; m_vdBlobs_Y[i] = m_vBlobs[i].m_dYCenter; m_vdBlobs_Orientation[i] = m_vBlobs[i].m_dOrientation; } same_frame = (sc >= m_iNObj - 2); if(same_frame) { return; } /* Tracking / UKF / State Estimation * * Now that we've got the mapping of which measurement goes with * which object, we need to feed the measurements into the UKF in * order to obtain a state estimate. * * This is a loop over each object we're tracking. */ for(unsigned int i = 0; i< m_iNObj; i++) { /* we could throw out a measurement and use the blob state as an estimate for various reasons. On the first frame we want to set the initial state, so we flag the measurement as invalid */ bool invalid_meas = m_vbNoMeasurement[i]; bool need_state = m_iFrameCounter == 1; /* if any state is NaN, reset the UKF * This shouldn't happen anymore, but it's a decent safety * check. It could probably be omitted if we want to * optimize for speed... */ if(m_iFrameCounter > 1 && (!CvMatIsOk(m_vpUKF[i]->x) || !CvMatIsOk(m_vpUKF[i]->P))) { MT_UKFFree(&(m_vpUKF[i])); m_vpUKF[i] = MT_UKFInit(4, 2, 0.1); MT_UKFCopyQR(m_vpUKF[i], m_pQ, m_pR); need_state = true; } if(need_state) { cvSetReal2D(m_px0, 0, 0, m_vdBlobs_X[i]); cvSetReal2D(m_px0, 1, 0, m_vdBlobs_Y[i]); cvSetReal2D(m_px0, 2, 0, 0); cvSetReal2D(m_px0, 3, 0, 0); MT_UKFSetState(m_vpUKF[i], m_px0); } /* if we're going to accept this measurement */ if(!invalid_meas) { /* UKF prediction step, note we use function pointers to the fish_dynamics and fish_measurement functions defined above. The final parameter would be for the control input vector, which we don't use here so we pass a NULL pointer */ MT_UKFPredict(m_vpUKF[i], &dance_dynamics, &dance_measurement, NULL); /* finally, set the measurement vector z */ cvSetReal2D(m_pz, 0, 0, m_vdBlobs_X[i]); cvSetReal2D(m_pz, 1, 0, m_vdBlobs_Y[i]); MT_UKFSetMeasurement(m_vpUKF[i], m_pz); /* then do the UKF correction step, which accounts for the measurement */ MT_UKFCorrect(m_vpUKF[i]); } else { /* use the predicted state */ CvMat* xp = m_vpUKF[i]->x1; MT_UKFSetState(m_vpUKF[i], xp); } /* then constrain the state if necessary - see function * definition above */ constrain_state(m_vpUKF[i]->x, m_vpUKF[i]->x1, frame); /* grab the state estimate and store it in variables that will make it convenient to save it to a file. */ CvMat* x = m_vpUKF[i]->x; m_vdTracked_X[i] = cvGetReal2D(x, 0, 0); m_vdTracked_Y[i] = cvGetReal2D(x, 1, 0); m_vdTracked_Vx[i] = cvGetReal2D(x, 2, 0); m_vdTracked_Vy[i] = cvGetReal2D(x, 3, 0); /* take the tracked positions as the blob centers */ m_vBlobs[i].m_dXCenter = m_vdTracked_X[i]; m_vBlobs[i].m_dYCenter = m_vdTracked_Y[i]; /* predict blob locations */ CvMat* xp = m_vpUKF[i]->x1; m_vPredictedBlobs[i].m_dXCenter = cvGetReal2D(xp, 0, 0); m_vPredictedBlobs[i].m_dYCenter = cvGetReal2D(xp, 1, 0); /* If we wanted the predicted state, this would be how to get it */ /* CvMat* xp = m_vpUKF[i]->x1; */ } MT_writeDSGYABlobsToFile(m_vBlobs, "blobs-out.dat"); MT_writeDSGYABlobsToFile(m_vPredictedBlobs, "predicted-out.dat"); /* write data to file */ writeData(); }
void ParseTreeLablerForm::splitButtonClicked() { //get the text of the selected item const QModelIndex index = widget.treeView->selectionModel()->currentIndex(); QString selectedText = index.data(Qt::DisplayRole).toString(); string name = getCppString(selectedText); std::vector<pcl::PointIndices> clusters; Node nd(name); cout<<"in split seg"<<endl; if (nd.type == "Terminal") { undoNames.clear(); double radT=getValueOfType<double>(widget.radEdit->text()); double angleT=getValueOfType<double>(widget.angleEdit->text()); double colorT=getValueOfType<double>(widget.colorT->text()); int numNbr=getValueOfType<int>(widget.nbrEdit->text()); int segId = nd.id; pcl::PointCloud<PointT> segCloud; segCloud.header = cloud_orig.header; vector<int> originalIndices; undoAvl = true; cloud_undo=cloud_orig; for (int i = 0; i < (int)cloud_orig.points.size(); i++) { if ((int)cloud_orig.points[i].segment == segId) { segCloud.points.push_back(cloud_orig.points[i]); cloud_orig.points[i].segment=0; originalIndices.push_back(i); } } cout<<"oversegmenting this seg whihch had "<<segCloud.size()<<"with params"<<radT<<","<<angleT<<","<<numNbr<<endl; // segment(segCloud, clusters,radT,angleT,numNbr,true,colorT); SegmentPCDGraph<PointT> segmenter(angleT,radT,numNbr,colorT,100); segmenter.segment(segCloud,clusters); sort(clusters.begin(), clusters.end(), compareSegsDecreasing); // the old segment now contains the largest segment after splitting segNumToColor.clear(); segNumToColor[segId]=randColor(); cout<<clusters.size()<<" oversegments found"<<endl; for (size_t i = 0; i < clusters.size(); i++) { cout<<"cluster "<<i<<"has "<<clusters[i].indices.size()<<" points\n"; int newSegId; if(i==0) { newSegId=segId; } else { newSegId=(++typeMaxId["Terminal"]); } segNumToColor[newSegId]=randColor(); for (size_t j = 0; j < clusters[i].indices.size(); j++) { cloud_orig.points[originalIndices.at(clusters[i].indices[j])].segment = newSegId; } if(i==0) continue; string name="Terminal__"+lexical_cast<string>(newSegId)+"__split"+lexical_cast<string>(segId); QStandardItem *item = new QStandardItem(name.data()); nameToTreeNode[name] = item; undoNames.push_back(name); rootNode->appendRow(item); } colorSegs(segNumToColor, true); updatePCDVis(); QMessageBox::warning(this, tr("Parse Tree Labaler"), tr("IMPORTANT: undo operation should not be done after merging any newly created segments" "It will cause inconsistency"), QMessageBox::Ok,QMessageBox::Ok); } }
visit_handle Simulation:: get_curve( const string &name ) const { visit_handle h = VISIT_INVALID_HANDLE; if( strncmp(name.c_str(),"bubble",6) == 0 ) { const size_t id = strconv::to_size( name.c_str()+6, "bubble id"); assert(id>0); assert(id<=bubbles.count()); const Bubble *b = bubbles.first(); for(size_t iter=1;iter<id;++iter) b=b->next; assert(b); if( VisIt_CurveData_alloc(&h) == VISIT_OKAY ) { // copy bubble spots coordinates const size_t bn = b->size+1; vector<Real> bx(bn,0); vector<Real> by(bn,0); const Tracer *p = b->root; for( size_t i=1; i <= bn; ++i,p=p->next) { bx[i] = p->vertex.x; by[i] = p->vertex.y; } // make a curve visit_handle hcx,hcy; VisIt_VariableData_alloc( &hcx ); VisIt_VariableData_alloc( &hcy ); VisIt_VariableData_setDataD(hcx, VISIT_OWNER_COPY, 1, bn, bx()); VisIt_VariableData_setDataD(hcy, VISIT_OWNER_COPY, 1, bn, by()); VisIt_CurveData_setCoordsXY(h, hcx, hcy); } } if( name == "junctions" ) { if( VisIt_CurveData_alloc(&h) == VISIT_OKAY ) { // copy juntions coordinates const size_t nj = segmenter.num_junctions(); vector<Real> jx(nj,0); vector<Real> jy(nj,0); const Segments &segments = segmenter(); for( size_t i=segments.size(),j=1;i>0;--i) { const Segment &seg = *segments[i]; for( const Junction *J = seg.head;J;J=J->next) { assert(j<=nj); jx[j] = J->vertex.x; jy[j] = J->vertex.y; ++j; } } // make a curve visit_handle hcx,hcy; VisIt_VariableData_alloc( &hcx ); VisIt_VariableData_alloc( &hcy ); VisIt_VariableData_setDataD(hcx, VISIT_OWNER_COPY, 1, nj, jx()); VisIt_VariableData_setDataD(hcy, VISIT_OWNER_COPY, 1, nj, jy()); VisIt_CurveData_setCoordsXY(h, hcx, hcy); } } return h; }