Beispiel #1
0
void TFRZCompressBase::createCode_step(TFRZCodeBase& out_FRZCode,const TFRZ_Byte* src_windows,const TFRZ_Byte* src_cur,const TFRZ_Byte* src_end){
    out_FRZCode.pushDataInit(src_windows,src_cur,src_end);
    const int allDataSize=(int)(src_end-src_windows);
    
    TFRZ_Int32 nozipBegin=(TFRZ_Int32)(src_cur-src_windows);
    TFRZ_Int32 curIndex=nozipBegin+1;
    while (curIndex<allDataSize) {
        TFRZ_Int32 matchPos;
        TFRZ_Int32 matchLength;
        if (getBestMatch(out_FRZCode,curIndex,&matchPos,&matchLength,nozipBegin)){
            if (curIndex!=nozipBegin){//out no zip data
                out_FRZCode.pushNoZipData(nozipBegin,curIndex);
            }
            out_FRZCode.pushZipData(curIndex,matchPos,matchLength);
            
            curIndex+=matchLength;
            assert(curIndex<=allDataSize);
            nozipBegin=curIndex;
        }else{
            ++curIndex;
        }
    }
    if (nozipBegin<allDataSize)
        out_FRZCode.pushNoZipData(nozipBegin,(TFRZ_Int32)allDataSize);
}
Beispiel #2
0
static void getBestMatches(struct pslSets *ps, int iSet, struct psl *psl)
/* find best matches to this psl in other sets and setup pslMatches object */
{
struct pslMatches *pm = setupMatches(ps, iSet, psl);
int iSet2;

for (iSet2 = iSet+1; iSet2 < ps->numSets; iSet2++)
    {
    struct psl *psl2 = getBestMatch(ps, iSet2, psl);
    if (psl2 != NULL)
        {
        pm->psls[iSet2] = psl2;
        pm->tStart = min(pm->tStart, psl2->tStart);
        pm->tEnd = min(pm->tEnd, psl2->tEnd);
        }
    }
}
Beispiel #3
0
const string& BotBrain::ask(const string& question) 
{
	vector<int> candidateAnswers(MAX_KNOWLEDGE_ENTRIES, 0);

	// returns all matching pre-built quries with close enough match
	findAllMatches(question, candidateAnswers);
	
	// returns the pre-built query that matches closely to the question
	pair<int, int> occurance(-1, -1);
	getBestMatch(occurance, candidateAnswers);

	// returns the corresponding answer.
	const string& defaultAnswer = getDefaultAnswer();
	if (occurance.second > 0) {
		return knowledgeBase[occurance.first].second;
	}

	return defaultAnswer;
}
Beispiel #4
0
//寻找合适的覆盖线.
static void search_cover(TDiffData& diff){
    const TSuffixString sstring((const char*)diff.oldData,(const char*)diff.oldData_end);
    
    TInt32 newPos=0;
    TInt32 lastOldPos=0;
    TInt32 lastNewPos=0;
    while (diff.newData_end-(diff.newData+newPos)>=kMinMatchLength) {
        TInt32 curOldPos;
        TInt32 curEqLength;
        bool isMatched=getBestMatch(sstring,diff.newData+newPos,diff.newData_end, &curOldPos,&curEqLength,kMinMatchLength);
        if (isMatched){
            assert(curEqLength>=kMinMatchLength);
            const TInt32 lastLinkEqLength=getLinkEqualCount(newPos,newPos+curEqLength,lastOldPos+(newPos-lastNewPos),diff);
            if ((curEqLength<lastLinkEqLength+kUnLinkLength)&&(newPos-lastNewPos>0)){//use link
                const TInt32 linkEqLength=getEqualLength(diff.oldData+lastOldPos+(newPos-lastNewPos), diff.oldData_end,diff.newData+newPos, diff.newData_end);
                const TInt32 linkLength=(newPos-lastNewPos)+linkEqLength;
                if (diff.cover.empty()){
                    diff.cover.push_back(TOldCover(lastNewPos,lastOldPos,linkLength));
                }else{
                    TOldCover& curCover=diff.cover.back();
                    curCover.length+=linkLength;
                }
                newPos+=std::max(linkEqLength,curEqLength);//实际等价于+=curEqLength;
            }else{ //use match
                diff.cover.push_back(TOldCover(newPos,curOldPos,curEqLength));
                newPos+=curEqLength;
            }
            TOldCover& curCover=diff.cover.back();
            lastOldPos=curCover.oldPos+curCover.length;
            lastNewPos=curCover.newPos+curCover.length;
        }else{
            ++newPos;//下一个需要匹配的字符串.
            //匹配不成功时,速度会比较慢.
        }
    }
}
Beispiel #5
0
int lineToTokens(const char *line,const char *symtab,const char *outfile,NFA *N,int nfaCount){
	int lbegin=0;
	int bestmatch;
	int match1,match2;
	int Code[MAXNFACOUNT];
	int End[MAXNFACOUNT];
	attrType Attrib[MAXNFACOUNT];
	for(int i=0;i<MAXNFACOUNT;i++){
		Attrib[i].string=(char *)malloc(sizeof(char)*100);
	}
	while(1){
		for(int i=0;i<nfaCount;i++){
			simulate_NFA(&N[i],line,lbegin,&End[i],&Attrib[i]);
		}
		getBestMatch(End,nfaCount,&match1,&match2);
		printf("\nMatch1 = %d\tMatch2 = %d",match1,match2);
		if(match2==-1){
			bestmatch=match1;
		}else if(match1==match2){
			if(getNFAID(&N[match1])==IDNTIFIER){
				bestmatch=match2;
			}else{
				bestmatch=match1;
			}
		}else{
			printf("\nFatal error in matching !!\n");
			exit(-1);
		}
		lbegin=End[bestmatch];
		switch(Code[bestmatch]){
			case IDNTIFIER:{
				addIdentifier(&Attrib[bestmatch],symtab,outfile);
				break;
			}
			case INT_CONST:{
				add_Numerical(&Attrib[bestmatch],symtab,outfile,INT_CONST);
				break;	
			}
			case FLO_CONST:{
				add_Numerical(&Attrib[bestmatch],symtab,outfile,FLO_CONST);
				break;
			}
			case NOTOK:{
				printf("\nLexeme not detected in any of the NFA !!!\n");
				exit(-1);
				// break;
			}
			default:{
				if((Code[bestmatch]>=422)&&(Code[bestmatch]<=445)){
					// treat lexeme as keyword
					addKeyWord(&Attrib[bestmatch],symtab,outfile,code[bestmatch]);
				}else{
					// treat lexeme as symbol
					add_Symbol(&Attrib[bestmatch],symtab,outfile,code[bestmatch]);
				}
			}
		}
		lbegin=End[bestmatch];
		if(line[lbegin]=='\0'){
			// we have reached the End of the current line
			break;
		}
		if(line[lbegin]==' '){
			lbegin++;
			continue;
		}
	}

	for(int i=0;i<MAXNFACOUNT;i++){
		free(Attrib[i].string);
		Attrib[i].string=NULL;
	}
}
int main(int argc, char** argv) {
	clock_t begin = clock();

	cvtColor(image0, image0, CV_BGR2Lab);
	cvtColor(image1, image1, CV_BGR2Lab);

	image0 = addWindowFrames(image0);
	image1 = addWindowFrames(image1);

	cv::Size outputSize = image0.size();
	cv::Mat output = cv::Mat::zeros(outputSize.height, outputSize.width, CV_8UC1);

	int row;
	int column;
	int minValue = 0;
	int maxValue = 0;

	std::cout << "Calculating disparity map...\n";
	for(row = WINDOW_SIZE; row < outputSize.height - WINDOW_SIZE; row++) {
		std::cout << "\r" << ((row * 100) / outputSize.height) << "% ";
		std::cout.flush();

		for(column = WINDOW_SIZE; column < outputSize.width - WINDOW_SIZE; column++) {

			cv::Point currentPosition = cv::Point(column, row);
			cv::Point bestMatch = getBestMatch(currentPosition);
			float disparity = distanceBetween(currentPosition, bestMatch);
			output.at<uchar>(row, column) = disparity * SCALE;
//			std::cout << "\nDisparity Found: " << disparity << " Image value: " << output.at<uchar>(row, column);

			if(disparity > maxValue) {
				maxValue = disparity;
			}
			if(disparity < minValue) {
				minValue = disparity;
			}
		}
	}

	std::cout << "\nImage min value: " << minValue << "\nImage max value: " << maxValue << "\n";

	// Normalizing image
//	for (row = 0; row < outputSize.height; row++) {
//		for (column = 0; column < outputSize.width; column++) {
//			float value = ((((float)output.at<uchar>(row, column) - (float)minValue)) / (float) maxValue) * 255.0;
//			output.at<uchar>(row, column) = (int)value;
//		}
//	}
	std::cout << "\n";
	// End image normalization

	output = removeWindowFrames(output);

	clock_t end = clock();
	double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
	std::cout << "It took " << elapsed_secs << " seconds";
	std::stringstream ss;

	// Makes no difference
	//	cv::medianBlur(output, output, 7);

	ss << "out/disparity_map_" << SET << "_" << METHOD << "_" << WINDOW_SIZE << ".png";
	cv::imwrite(ss.str(), output);

	cv::namedWindow("Gray image", CV_WINDOW_AUTOSIZE);
	cv::imshow("Gray image", output);
	cv::waitKey(0);
	return 0;
}