int evalRPN(vector<string> &tokens) {
        int ret;
        stack<int> stk;
        for(int i=0; i<tokens.size(); ++i)
            {
                if(tokens[i].size() == 1)
                    {//this string may be an operator
                        switch(tokens[i][0])
                            {
                                case '+':
                                    {
                                        int a = stk.top();  stk.pop();
                                        int b = stk.top();  stk.pop();
                                        stk.push(a+b);
                                        break;
                                    }
#if 1
                                case '-':
                                    {
                                        //be careful!!!!
                                        //it's b-a not a-b!!!!
                                        int a = stk.top();  stk.pop();
                                        int b = stk.top();  stk.pop();
                                        stk.push(b-a);
                                        break;
                                    }
                                case '*':
                                    {
                                        int a = stk.top();  stk.pop();
                                        int b = stk.top();  stk.pop();
                                        stk.push(a*b);
                                        break;
                                    }
                                case '/':
                                    {
                                        //be careful!!!!
                                        //it's b/a not a/b!!!!!
                                        int a = stk.top();  stk.pop();
                                        int b = stk.top();  stk.pop();
                                        stk.push(b/a);
                                        break;
                                    }
#endif
                                default:
                                    {
                                        int a = strnum(tokens[i]);
                                        stk.push(a);
                                    }
                            }
                    }
                else
                    {
                        int a = strnum(tokens[i]);
                        stk.push(a);
                    }
            }
        return stk.top();
    }
Пример #2
0
static void report_gui_total(report_gui_t *rg)
{
  if ( rg->out != NULL )
    gtk_label_set_text(GTK_LABEL(rg->total), strnum(rg->out->stat.ncase));
  else
    gtk_label_set_text(GTK_LABEL(rg->total), "0");
}
Пример #3
0
void BackGround::OutputBackground(double scale,double scalefactor,double step)
{
	cv::Rect currentroi;
	currentroi.width=m_bgroi.width;
	currentroi.height=m_bgroi.height;
	for(;currentroi.width<m_input.cols || currentroi.height<m_input.rows;)
	{
		currentroi.x=0;
		currentroi.y=0;
		for(;currentroi.x+currentroi.width<m_input.cols;currentroi.x=(int)(currentroi.x+currentroi.width*step))
		{
			for(;currentroi.y+currentroi.height<m_input.rows;currentroi.y=(int)(currentroi.y+currentroi.height*step))
			{
				cv::Mat imgtmp=m_input(currentroi);
				cv::Mat imgtmp_target(m_bgroi.height,m_bgroi.width,m_input.type());
				cv::resize(imgtmp,imgtmp_target,cv::Size(m_bgroi.width,m_bgroi.height));

				char num[65535];
//				char num[NUMLENGTH];
#ifdef WIN32
				_itoa_s(m_total++,num,10);
#else
				itoa(m_total++,num,10);
#endif
				string strnum(num);
				cv::imwrite(m_outputdir+m_prefix+string("_")+strnum+string(".jpg"),imgtmp_target);
			}
		}
		currentroi.width=(int)(m_bgroi.width*scale);
		currentroi.height=(int)(m_bgroi.height*scale);
		scale*=scalefactor;
	}
}
Пример #4
0
STR convarg3(STR a, MTNJOB *j)
{
  int m;
  int n;
  STR s;
  char *b;

  if(!strcmp(a, "H")){
    if(j->svr){
      a = modstr(a, j->svr->host);
    }else{
      a = modstr(a, "local");
    }
    return(a);
  }

  b = malloc(ctx->arg_max);
  a = strnum(a, b);
  if(!strlen(b)){
    s = joinarg(j->argl, ctx->delim);
  }else{
    n = atoi(b);
    m = cntarg(j->argl);
    s = newstr((n < m) ? j->argl[n] : "");
  }
  free(b);
  b = NULL;
  a = convarg4(a, s);
  clrstr(s);
  return(a);
}
Пример #5
0
void
Numput(unsigned int i)
{
    char buf[20];

    strnum((unsigned char *)buf, i);
    Mprint(buf);
}
Пример #6
0
void
Numerr(unsigned int i)
{
    char buf[20];

    strnum((unsigned char *)buf, i);
    Merr(buf);
}
Пример #7
0
void BlockEdgeDetectorT::doRight()
{
	const int ROI_WIDTH = 66;
	const int ROI_HEIGHT = 50;
	int inc = 25;//(float)(endY - startY) / 60 + 0.5;//范围增量

	int index = 0;
	vector<cv::Mat> reduceList;
	vector<cv::Point> points;
	//右边界
	int startY = p_block->B.y + 150;
	int endY = p_block->D.y - 150;
	for (int y = startY; y < endY && y < image.rows; y += inc, index++)
	{
		int y1 = y;
		if (y1 < 0 || y1 >= image.rows)
			continue;
		if ((y1 + ROI_HEIGHT) >= endY)
			y1 = endY - ROI_HEIGHT - 1;
		if ((y1 + ROI_HEIGHT) >= image.rows)
			y1 = image.rows - ROI_HEIGHT - 1;

		int x = p_block->GetPonintByY(y1, &p_block->RightLine).x;
		if (x < 0 || x >= image.cols)
			continue;

		cv::Mat tmpROI = image(cv::Rect(x - ROI_WIDTH, y1, ROI_WIDTH, ROI_HEIGHT)).clone();
		cv::GaussianBlur(tmpROI, tmpROI, cv::Size(5, 5), 0);
#ifdef BED_OUTPUT_DEBUG_INFO
		debug_rights.push_back(tmpROI);
#endif
		tmpROI.convertTo(tmpROI, CV_32F);

		cv::Mat reduceImg;
		cv::reduce(tmpROI, reduceImg, 0, CV_REDUCE_AVG);
		cv::resize(reduceImg, reduceImg, cv::Size(reduceImg.cols / 2, reduceImg.rows));//宽缩减为一半

#ifdef SAVE_IMG
		//保存图片
		char num[10];
		sprintf(num, "%03d", index);
		string strnum(num);
		stringstream ss;
		ss << "EdgeInner\\R\\右_" << strnum << "_reduce.jpg";
		cv::imwrite(ss.str(), reduceImg);
		ss.str("");
		ss << "EdgeInner\\R\\右_" << strnum << ".jpg";
		cv::imwrite(ss.str(), tmpROI);
#endif

		//reduceImg.convertTo(reduceImg, CV_32F);
		reduceList.push_back(reduceImg);
		points.push_back(p_block->GetPonintByY(y, &p_block->RightLine));
	}
	processLeftRight(reduceList, points);
}
int main()
{
    char a[100],tmp,**encode;
    HTree *T;
    int n,i,j,r,k;
    dat rcd[100];
    printf("随便输入一串字符(可以包括空隔、字母、符号等):\n");
    while(*gets(a)=='\0');//用gets()输入,字符串可以存储空隔
    strnum(a,&n,rcd);//统计函数
    printf("原码为:%s\n",a);
    CreatHTree(&T,rcd,n);
    /*下面的二重循环是对rcd[].code的字符反向存放*/
    for(i=0; i<n; i++)
    {
        r=strlen(rcd[i].code);
        for(j=0,k=r; j<r/2; j++)
        {
            tmp=rcd[i].code[j];
            rcd[i].code[j]=rcd[i].code[k-1];
            rcd[i].code[k-1]=tmp;
            k--;
        }
    }
    printf("-----------------------\n权值  字符   编码 \n");
    for(i=0; i<n; i++)
    {
        printf("%4d %4c %7s\n",rcd[i].w,rcd[i].ch,rcd[i].code);
    }
    printf("-----------------------\n");
    encode=(char **)malloc(strlen(a)*sizeof(char*));//encode存放原字符串的译码
    //下面的二重循环是当原字符串逐个编译,存放在encode中
    for(i=0,r=0; i<strlen(a); i++)
    {
        for(j=0; j<n; j++)
            if(a[i]==rcd[j].ch)
                break;
        encode[i]=(char*)malloc(strlen(rcd[j].code+1));
        strcpy(encode[i],rcd[j].code);
    }
    printf("字符串被编码为:\n");
    for(i=0; i<strlen(a); i++)
        printf("%s",encode[i]);
    printf("\n准备执行解码程序...\n");
    system("pause");
    Decode(rcd,encode,n,strlen(a));//解码
    return 1;
}
Пример #9
0
void report_gui_executed(report_gui_t *rg, unsigned long key, tree_result_t *result)
{
  output_stat_t *stat = &(rg->out->stat);
  float n = (float) (stat->ncase);
  int significant = stat->passed + stat->failed + stat->inconclusive;

  /* Update significant test counter */
  gtk_label_set_text(GTK_LABEL(rg->significant), strnum(significant));

  /* Update progress bars */
  report_gui_progress(rg->executed, (float) (stat->executed) / n);
  report_gui_progress(rg->skip, (float) (stat->skip) / n);
  if ( significant > 0 ) {
    report_gui_progress(rg->passed, (float) (stat->passed) / (float) significant);
    report_gui_progress(rg->failed, (float) (stat->failed) / (float) significant);
    report_gui_progress(rg->inconclusive, (float) (stat->inconclusive) / (float) significant);
  }

  /* Update test case list */
  report_gui_list_verdict(rg, key, result);
}
Пример #10
0
void BackGround::OutputBackground_OnePass(cv::Size win_stride)
{
	cv::Rect currentroi;
	currentroi.width=m_bgroi.width;
	currentroi.height=m_bgroi.height;
	int stridewidth = win_stride.width;
	int strideheight = win_stride.height;
	int i,j;
	int purecolor = m_bgroi.width*m_bgroi.height*255;
	cv::Scalar colorsum;
	for (j=0; (j+currentroi.height) < m_input.rows; j+=strideheight)
	{
		for (i=0; (i+currentroi.width) < m_input.cols; i+=stridewidth)
		{
			currentroi.x=i;
			currentroi.y=j;
			cv::Mat imgtmp=m_input(currentroi);
			colorsum = cv::sum(imgtmp);
			if (colorsum[0] == purecolor)
			{
				continue;
			}
			
			char num[65535];
			//				char num[NUMLENGTH];
#ifdef WIN32
			_itoa_s(m_total++,num,10);
#else
			itoa(m_total++,num,10);
#endif
			string strnum(num);
			cv::imwrite(m_outputdir+m_prefix+string("_")+strnum+string(".jpg"),imgtmp);

		}
	}
}
Пример #11
0
void BlockEdgeSimilarDetector::doUp()
{
	// 如果左边界直接在图像边缘上,则不进行检测。
	if (p_block->A.y < 2 && p_block->B.y < 2)
		return;


	//计算出上边缘的倒角深度,以该深度取ROI比较相似度

	//int deep1 = getDeepUp(p_block->GetPonintByX((p_block->A.x + p_block->B.x) / 2, &p_block->UpLine));//中点深度
	//int deep2 = getDeepUp(p_block->GetPonintByX((2 * p_block->A.x + p_block->B.x) / 3, &p_block->UpLine));//1/3点深度
	//int deep3 = getDeepUp(p_block->GetPonintByX((p_block->A.x + 2 * p_block->B.x) / 3, &p_block->UpLine));//2/3点深度

	//ROI_HEIGHT_UP = min(deep1, deep2);
	//ROI_HEIGHT_UP = min(ROI_HEIGHT_UP, deep3);

	int index = 0;
	vector<cv::Mat> reduceList;
	vector<cv::Point> points;

	//上边界
	int startX = p_block->A.x + 55;
	if (startX < 0)
		startX = 0;
	int endX = p_block->B.x - 55;
	if (endX >= image.cols)
		endX = image.cols - 1;

	for (int x = startX; x < endX && x < image.cols; x += ROI_WIDTH_INC, index++)
	{
		int x1 = x;
		if (x < 0 || x >= image.cols)
			continue;
		if ((x + ROI_WIDTH_UPDOWN) >= endX)
			x1 = endX - ROI_WIDTH_UPDOWN - 1;
		if ((x + ROI_WIDTH_UPDOWN) >= image.cols)
			x1 = image.cols - ROI_WIDTH_UPDOWN - 1;

		int y = p_block->GetPonintByX(x1, &p_block->UpLine).y;
		if (y < 0 || y >= image.rows)
			continue;

		cv::Mat tmpROI = image(cv::Rect(x1, y, ROI_WIDTH_UPDOWN, ROI_HEIGHT_UP)).clone();
		cv::GaussianBlur(tmpROI, tmpROI, cv::Size(5, 5), 0);
#ifdef BED_OUTPUT_DEBUG_INFO
		debug_ups.push_back(tmpROI);
#endif
		tmpROI.convertTo(tmpROI, CV_32F);

		cv::Mat reduceImg;
		cv::reduce(tmpROI, reduceImg, 1, CV_REDUCE_AVG);
		cv::GaussianBlur(reduceImg, reduceImg, cv::Size(3, 3), 0);
		//cv::resize(reduceImg, reduceImg, cv::Size(reduceImg.cols, reduceImg.rows / 2));//高度缩减为一半

#ifdef SAVE_IMG
		//保存图片
		char num[10];
		sprintf(num, "%03d", index);
		string strnum(num);
		stringstream ss;
		ss << "BlockEdgeSimilarDetector\\up\\上_" << strnum << "_reduce.jpg";
		cv::imwrite(ss.str(), reduceImg);
		ss.str("");
		ss << "BlockEdgeSimilarDetector\\up\\上_" << strnum << ".jpg";
		cv::imwrite(ss.str(), tmpROI);
		cv::Mat hist(100, reduceImg.rows, CV_8U, cv::Scalar(0));
		for (size_t y = 0; y < reduceImg.rows; y++)
		{
			int count = reduceImg.ptr<float>(y)[0];
			int x = y;
			for (int i = 99; i >= 0 && count > 0; i--)
			{
				count--;
				hist.ptr<uchar>(i)[x] = 255;
			}
		}
		ss.str("");
		ss << "BlockEdgeSimilarDetector\\up\\上_" << strnum << "hist.jpg";
		cv::imwrite(ss.str(), hist);
#endif

		tmpROI.release();
		reduceList.push_back(reduceImg);
		points.push_back(cv::Point(x, p_block->GetPonintByX(x, &p_block->UpLine).y));
	}
	process(reduceList, points, "up");
}
Пример #12
0
void BlockEdgeSimilarDetector::doRight()
{
	// 如果边界直接在图像边缘上,则不进行检测。
	if (p_block->B.y >= image.cols - 2 && p_block->C.y >= image.cols - 2)
		return;

	int index = 0;
	vector<cv::Mat> reduceList;
	vector<cv::Point> points;
	//右边界
	int startY = p_block->B.y + 69;
	if (startY < 0)
		startY = 0;
	int endY = p_block->C.y - 69;
	if (endY >= image.rows)
		endY = image.rows - 1;
	for (int y = startY; y < endY && y < image.rows; y += ROI_HEIGHT_INC, index++)
	{	
		int y1 = y;
		if (y1 < 0 || y1 >= image.rows)
			continue;
		if ((y1 + ROI_HEIGHT_LEFTRIGHT) >= endY)
			y1 = endY - ROI_HEIGHT_LEFTRIGHT - 1;
		if ((y1 + ROI_HEIGHT_LEFTRIGHT) >= image.rows)
			y1 = image.rows - ROI_HEIGHT_LEFTRIGHT - 1;

		int x = p_block->GetPonintByY(y1, &p_block->RightLine).x;
		if (x < 0 || x >= image.cols)
			continue;

		cv::Mat tmpROI = image(cv::Rect(x - ROI_WIDTH_LEFTRIGHT, y1, ROI_WIDTH_LEFTRIGHT, ROI_HEIGHT_LEFTRIGHT)).clone();
		cv::GaussianBlur(tmpROI, tmpROI, cv::Size(5, 5), 0);
#ifdef BED_OUTPUT_DEBUG_INFO
		debug_rights.push_back(tmpROI);
#endif
		tmpROI.convertTo(tmpROI, CV_32F);

		cv::Mat reduceImg;
		cv::reduce(tmpROI, reduceImg, 0, CV_REDUCE_AVG);
		cv::GaussianBlur(reduceImg, reduceImg, cv::Size(3, 3), 0);
		//cv::resize(reduceImg, reduceImg, cv::Size(reduceImg.cols / 2, reduceImg.rows));//宽缩减为一半

		reduceImg = reduceImg.t();
#ifdef SAVE_IMG
		//保存图片
		char num[10];
		sprintf(num, "%03d", index);
		string strnum(num);
		stringstream ss;
		ss << "BlockEdgeSimilarDetector\\right\\右_" << strnum << "_reduce.jpg";
		cv::imwrite(ss.str(), reduceImg);
		ss.str("");
		ss << "BlockEdgeSimilarDetector\\right\\右_" << strnum << ".jpg";
		cv::imwrite(ss.str(), tmpROI);
		cv::Mat hist(100, reduceImg.rows, CV_8U, cv::Scalar(0));
		for (size_t y = 0; y < reduceImg.rows; y++)
		{
			int count = reduceImg.ptr<float>(y)[0];
			int x = y;
			for (int i = 99; i >= 0 && count > 0; i--)
			{
				count--;
				hist.ptr<uchar>(i)[x] = 255;
			}
		}
		ss.str("");
		ss << "BlockEdgeSimilarDetector\\right\\右_" << strnum << "hist.jpg";
		cv::imwrite(ss.str(), hist);
#endif
		tmpROI.release();
		reduceList.push_back(reduceImg);
		points.push_back(p_block->GetPonintByY(y, &p_block->RightLine));
	}
	process(reduceList, points, "right");
}
int main()
{
    char a[100],tmp,**encode,*cd;
    HTree *T;
    int n,i,j,r,k,choice,flag=0;
    dat rcd[100];
    while(1)
    {
        printf("\t\t-------------------------------------\n\t\t1、对电文对行编码   2、解码   3、退出\n\t\t************************************\n");
        printf("请操作。。。\n");
        scanf("%d",&choice);
        if(choice==1)
        {
            printf("随便输入一串字符(可以包括空隔、字母、符号等):\n");
            while(*gets(a)=='\0');//用gets()输入,字符串可以存储空隔
            strnum(a,&n,rcd);//统计函数
            printf("原码为:%s\n",a);
            flag=CreatHTree(&T,rcd,n);
            /*下面的二重循环是对rcd[].code的字符反向存放*/
            for(i=0; i<n; i++)
            {
                r=strlen(rcd[i].code);
                for(j=0,k=r; j<r/2; j++)
                {
                    tmp=rcd[i].code[j];
                    rcd[i].code[j]=rcd[i].code[k-1];
                    rcd[i].code[k-1]=tmp;
                    k--;
                }
            }
            printf("-----------------------\n权值  字符   编码 \n");
            for(i=0; i<n; i++)
                printf("%4d %4c %7s\n",rcd[i].w,rcd[i].ch,rcd[i].code);
            printf("-----------------------\n");
            encode=(char **)malloc(strlen(a)*sizeof(char*));//encode存放原字符串的译码
            //下面的二重循环是当原字符串逐个编译,存放在encode中
            for(i=0,r=0; i<strlen(a); i++)
            {
                for(j=0; j<n; j++)
                    if(a[i]==rcd[j].ch)
                        break;
                r=r+strlen(rcd[j].code);
                encode[i]=(char*)malloc(strlen(rcd[j].code+1));
                strcpy(encode[i],rcd[j].code);
            }
            printf("字符串被编码为:\n");
            cd=(char *)malloc(r*sizeof(char)+1);
            strcpy(cd,encode[0]);
            for(i=1; i<strlen(a); i++)
                strcat(cd,encode[i]);
            free(encode);
            printf("\n%s",cd);
        }
        if(choice==2)
        {
            if(flag!=1)
                printf("请先对电报编码!\n");
            else
                Decode(T,cd,rcd,2*n-1);//解码
        }
        if(choice==3) break;
        if(choice>3||choice<1)
            printf("您的输入有误,请重新输入!\n");
        system("pause");
        system("cls");

    }
    return 1;
}