コード例 #1
0
void fp_AnnotationRun::recalcValue(void)
{
    _recalcWidth();
    if(!displayAnnotations())
    {
        m_iRealWidth = calcWidth();
    }
}
コード例 #2
0
bool fp_AnnotationRun::_recalcWidth(void)
{
    if(!displayAnnotations())
    {
        if(getWidth() == 0)
	    return false;
	clearScreen();
	markAsDirty();
	if(getLine())
	{
	    getLine()->setNeedsRedraw();
	}
	if(getBlock())
	{
	    getBlock()->setNeedsRedraw();
	}
	_setWidth(0);
	return true;
    }
    if(!m_bIsStart)
    {
	_setWidth(0);
	return false;
    }
    UT_sint32 iNewWidth = calcWidth();
    m_iRealWidth = iNewWidth;

    if (iNewWidth != getWidth())
    {
	clearScreen();
	markAsDirty();
	if(getLine())
	  {
	    getLine()->setNeedsRedraw();
	  }
	if(getBlock())
	  {
	    getBlock()->setNeedsRedraw();
	  }
	_setWidth(iNewWidth);
	return true;
    }
    return false;
}
コード例 #3
0
void fp_AnnotationRun::_draw(dg_DrawArgs* pDA)
{
        if(!displayAnnotations())
	  return;
	if(!m_bIsStart)
	  return;

	GR_Graphics * pG = pDA->pG;

	UT_sint32 xoff = 0, yoff = 0;
	GR_Painter painter(pG);

	// need screen locations of this run

	getLine()->getScreenOffsets(this, xoff, yoff);

	UT_sint32 iYdraw =  pDA->yoff - getAscent()-1;

	UT_uint32 iRunBase = getBlock()->getPosition() + getBlockOffset();

//
// Sevior was here
//		UT_sint32 iFillTop = iYdraw;
	UT_sint32 iFillTop = iYdraw+1;
	UT_sint32 iFillHeight = getAscent() + getDescent();

	FV_View* pView = _getView();
	UT_uint32 iSelAnchor = pView->getSelectionAnchor();
	UT_uint32 iPoint = pView->getPoint();

	UT_uint32 iSel1 = UT_MIN(iSelAnchor, iPoint);
	UT_uint32 iSel2 = UT_MAX(iSelAnchor, iPoint);

	UT_ASSERT(iSel1 <= iSel2);
	bool bIsInTOC = getBlock()->isContainedByTOC();
	if (
	    isInSelectedTOC() || (!bIsInTOC && (
						/* pView->getFocus()!=AV_FOCUS_NONE && */
						(iSel1 <= iRunBase)
						&& (iSel2 > iRunBase)))
	    )
	{
	    UT_RGBColor color(_getView()->getColorSelBackground());			
	    pG->setColor(_getView()->getColorAnnotation(this));
	    painter.fillRect(color, pDA->xoff, iFillTop, getWidth(), iFillHeight);

	}
	else
        {
	    Fill(getGraphics(),pDA->xoff, iFillTop, getWidth(), iFillHeight);
	    pG->setColor(_getColorFG());
	}
	pG->setFont(_getFont());
	pG->setColor(_getView()->getColorAnnotation(this));
	UT_DEBUGMSG(("Drawing string m_sValue %s \n",m_sValue.utf8_str()));
	painter.drawChars(m_sValue.ucs4_str().ucs4_str(), 0,m_sValue.ucs4_str().size(), pDA->xoff,iYdraw, NULL);
//
// Draw underline/overline/strikethough
//
	UT_sint32 yTopOfRun = pDA->yoff - getAscent()-1; // Hack to remove
	                                                 //character dirt
	drawDecors( xoff, yTopOfRun,pG);

}
コード例 #4
0
ファイル: genhardnegatives.cpp プロジェクト: lucky384/pdiue
void genHardNegativesOnAnnotations(FeatGen* ldgFeatGen,const path& baseDir, datasets currDataset, bool writeOutWins, bool viz,string modelfile)
{
	vector<path> negativePaths;
	vector<path> negTrainPaths;
	vector<path> negTestPaths;
	FrameId firstTestFrame; // separates training and testing data
	string learnFileStem;
	vector<path> normPosWinPathsTrain; // if any use folder with normalized cropped windows
		vector<path> normPosWinPathsTest; // if any use folder with normalized cropped windows
	getLearnInfos(baseDir, currDataset, negativePaths, negTrainPaths, negTestPaths,normPosWinPathsTrain, normPosWinPathsTest, learnFileStem, firstTestFrame);

	path negTrainFolder = baseDir / "learning" / "train_neg_hard_annot";
	remove_all(negTrainFolder);
	create_directories(negTrainFolder);

	//std::ios_base::openmode mode = ;
	//fs::ofstream trainFile((baseDir / "learning" / learnFileStem).string(), std::ios_base::out | ios_base::app);
	//fs::ofstream trainFilesFile((baseDir / "learning" / learnFileStem).string() + ".files", std::ios_base::out | ios_base::app);

	fs::ofstream trainFileHard((baseDir / "learning" / learnFileStem).string() + "_hard_annot");


	if ( !(modelfile.length() > 0 ) )
	{
		modelfile = (baseDir / "learning" / learnFileStem).string() + ".model";
	}
	path mfp(modelfile);
	if ( !exists(mfp))
	{
		cerr << "Modelfile does not exist: " << modelfile << endl;
		exit(EXIT_FAILURE);
	}
	cout << "genHardNegativesOnAnnotations using model: " << modelfile << endl;
	Detector pd(ldgFeatGen);
	pd.setStartScale(1.0);
	pd.setScaleStep(1.04);
	pd.loadSVMWeights(modelfile);
	float decThresh = 0;

	int nww = ldgFeatGen->getWinW();
	int nwh = ldgFeatGen->getWinH();

	// use caltech annotations
	FrameId startFrame;
	startFrame.set= 0;
	startFrame.video= 0;
	startFrame.image= 0;

	size_t featSize = getFeatLen(ldgFeatGen);

			vector<path> annotFiles;
			annotFiles = findAllAnnotations(baseDir,startFrame);

			if ( annotFiles.size() == 0 )
			{
				cerr << "No annotations found." << endl;
				exit(EXIT_FAILURE);
			}

			for ( vector<path>::iterator it (annotFiles.begin()); it != annotFiles.end(); ++it)
			{
				path vbbFile = *it;
				path txtFolder = vbbFile.parent_path() / vbbFile.stem();

				vector<path> v;
				copy(directory_iterator(txtFolder),directory_iterator(),back_inserter(v));

				sort(v.begin(),v.end());
				int posTrainCounter = 0;
				cout << "0% ";
				cout.flush();
				for ( vector<path>::iterator vit (v.begin()); vit != v.end(); ++vit)
				{
					path txtFile = *vit; // annotation txtFile

					// corresponding image file
					path imgFile = baseDir / "videos" / txtFile.parent_path().parent_path().stem() / txtFile.parent_path().stem() / txtFile.filename().stem();
					bool isTrain = true;

					if (frameLTEQ(firstTestFrame,parseFrameFromPath(imgFile)))
					{
						isTrain = false;
					}

					if ( skipPath(imgFile,startFrame) )
						continue;

					if ( !isTrain ) continue;

					imgFile += findImageExtension(imgFile);

					if ( !exists(imgFile) || !is_regular_file(imgFile))
					{
						cerr << "Could not find corresponding image file " <<imgFile <<endl;
						cerr << "Export all .seq files using provided matlab code." << endl;
						exit(EXIT_FAILURE);
					}

					// parse annotations from txtFile
					fs::ifstream f(txtFile);
					if (!f)
					{
						cerr << "cannot open file " << txtFile << endl;
						exit(EXIT_FAILURE);
					}

					vector<Annotation> annots;

					string buffer;
					while (std::getline(f,buffer))
					{
						Annotation a = parseAnnotation(buffer);
						if ( a.type == "person" )
						{
							//printAnnotation(a);
							annots.push_back(a);
						}

					}

					// extract normalized bb images
					Mat img = imread(imgFile.string(), CV_LOAD_IMAGE_COLOR);

					posTrainCounter++;
					if ( (posTrainCounter % 100) == 0)
					{
						float donePerc = posTrainCounter / (float)v.size();
						cout << floor(donePerc * 100) << "% ";
						cout.flush();
					}


					path nf = imgFile;
					string filePre  = nf.parent_path().parent_path().stem().string() + nf.parent_path().stem().string() +  "_" + nf.filename().stem().string();

					vector< pair < Detection,double* > > detections;
					vector<Detection> alldetections;
					pd.detect(img,detections,alldetections,decThresh,true);

					vector<bool> rectIsUsed;
					rectIsUsed.resize(detections.size());
					for ( size_t i = 0; i < detections.size(); i++)
					{
						pair < Detection,double* > mp = detections[i];
						Detection det = mp.first;
						Rect r = det.r;
						double* f = mp.second;

						// check if rectangle is annotated object
						bool rectIsFree = true;
						for (vector<Annotation>::iterator ait (annots.begin()); ait != annots.end(); ++ait)
						{
							Annotation an = *ait;
							Rect a(an.x,an.y,an.width,an.height);

							// calc intersection area
							Rect inters =  a & r;
							if ( inters.area() > 0 )
							{
								// further analyze intersection

								double ratio1 = (double) inters.area() / (double) r.area();
								double ratio2 = (double) inters.area() / (double) a.area();

								double ratio = min(ratio1,ratio2);


								rectIsFree = !(ratio > 0.5);
								if ( !rectIsFree )
								{
									break;
								}
							}
						}
						rectIsUsed[i] = rectIsFree;

						if ( rectIsFree )
						{
							// save as negative example
							writeFeatToSVMStream(f,trainFileHard,featSize,false);
						}
						else
						{
							// save as positive example
							writeFeatToSVMStream(f,trainFileHard,featSize,true);
						}

						delete[] f;

					}


					if ( viz || writeOutWins )
					{
						Mat vizImg = img.clone();
						if ( alldetections.size() < 100 )
						{
							for ( vector< Detection >::iterator it(alldetections.begin()); it != alldetections.end(); it++)
							{
								Detection det = *it;
								Rect r = det.rNormWin;

								//cout << r.x << " " << r.y << " " << r.width << "x" << r.height << " scale:" << det.scale << " decisionValue:" << det.decisionValue << endl;
								rectangle(vizImg,r,Scalar(255,50,50),1,8);

							}
						}

						for ( size_t i = 0; i < detections.size(); i++)
						{
							Detection det = detections[i].first;
							Rect r = det.r;

							if ( rectIsUsed[i])
							{
								rectangle(vizImg,r,Scalar(0,0,255),1,8);
							}
							else
							{
								rectangle(vizImg,r,Scalar(0,255,255),1,8);
							}

						}

						displayAnnotations(vizImg,annots);

						if ( writeOutWins )
						{
							string fileNameOnly = (filePre +"_hard.png");
							path nwPath = negTrainFolder / fileNameOnly;
							imwrite(nwPath.string(),vizImg);
						}
						if ( viz )
						{
							imshow("negative training image",vizImg);
							waitKey(0);
							destroyWindow("negative training image");
						}
					}


				}


			}
			cout << "100% "<< endl;
	trainFileHard.close();
}