Пример #1
0
void Chess_recognition::Get_Line(vector<pair<float, float>> *linesX, vector<pair<float, float>> *linesY){
	linesX->clear();
	linesY->clear();
	EnterCriticalSection(&vec_cs);
	copy(vec_LineX.begin(), vec_LineX.end(), back_inserter(*linesX));
	copy(vec_LineY.begin(), vec_LineY.end(), back_inserter(*linesY));
	LeaveCriticalSection(&vec_cs);

	mergeLine(linesX);
	mergeLine(linesY);
}
Пример #2
0
YOPTIMIZE_SPEED int
YmagineMergeLine(unsigned char *destpixels, int destmode, int destweight,
                 const unsigned char *srcpixels, int srcmode, int srcweight,
                 int width)
{
  int bpp;
  int rc = YMAGINE_ERROR;

  if (destweight < 0 || srcweight < 0 ||
      destpixels == NULL || srcpixels == NULL) {
    return rc;
  }

  if (destmode != srcmode) {
    /* now only supports merge lines with same color mode */
    return rc;
  }

  bpp = colorBpp(destmode);

  if (srcweight == 0) {
    /* Nothing to do */
    rc = YMAGINE_OK;
  } else if (destweight == 0) {
    memcpy(destpixels, srcpixels, width * bpp * sizeof(unsigned char));
    rc = YMAGINE_OK;
  } else {
    switch (destmode) {
    case VBITMAP_COLOR_GRAYSCALE:
      rc = mergeLine(destpixels, destweight, srcpixels, srcweight, width, 1, -1, 0);
      break;
    case VBITMAP_COLOR_RGB:
      rc = mergeLine(destpixels, destweight, srcpixels, srcweight, width, 3, -1, 0);
      break;
    case VBITMAP_COLOR_RGBA:
      rc = mergeLine(destpixels, destweight, srcpixels, srcweight, width, 4, 3, 0);
      break;
    case VBITMAP_COLOR_rgbA:
      rc = mergeLine(destpixels, destweight, srcpixels, srcweight, width, 4, 3, 1);
      break;
    case VBITMAP_COLOR_ARGB:
      rc = mergeLine(destpixels, destweight, srcpixels, srcweight, width, 4, 0, 0);
      break;
    case VBITMAP_COLOR_Argb:
      rc = mergeLine(destpixels, destweight, srcpixels, srcweight, width, 4, 0, 1);
      break;
    default:
      rc = mergeLine(destpixels, destweight, srcpixels, srcweight, width, bpp, -1, 0);
      break;
    }
  }

  return rc;
}
Пример #3
0
/* 将矢量化结果中的拐角线从拐点处断开,并先合并平行相连的线段
 * potrace_state 矢量化输出结果
 * lineSegments 拐角点断开并合并后的线段数组
 */
void breakCornerAndRecombine(potrace_state_t* potrace_state, SegmentsArray* lineSegments)
{
	int i;
	potrace_path_t* pNext = potrace_state->plist;
	while(pNext != NULL)
	{
		potrace_curve_t* curve = &(pNext->curve);
		/*****为lineSegments增加curve->n的数组长度*****/
		lineSegments->length = lineSegments->count+2*curve->n;
		CvPoint2D32f (*tempPointArray)[2];
		char* tempFlag;
		tempPointArray = (CvPoint2D32f(*)[2])malloc(sizeof(CvPoint2D32f[2]) * lineSegments->length);
		tempFlag = (char*)malloc(sizeof(char) * lineSegments->length);
		for(int m=0; m<lineSegments->count; m++)
		{
			tempPointArray[m][0] = lineSegments->pointArray[m][0];
			tempPointArray[m][1] = lineSegments->pointArray[m][1];
			tempFlag[m] = lineSegments->flag[m];
		}
		free(lineSegments->pointArray);
		free(lineSegments->flag);
		lineSegments->pointArray = tempPointArray;
		lineSegments->flag = tempFlag;

		for(i=0; i<curve->n; i++) //遍历闭合曲线中的每个片段
		{
			if(curve->tag[i] == POTRACE_CORNER) //如果是拐角线片段
			{
				lineSegments->flag[lineSegments->count] = 0;
				//每次循环存储的是当前拐角线的第二个直线片段和下一个拐角线的第一个直线片段
				lineSegments->pointArray[lineSegments->count][0].x = (float)curve->c[i][1].x;
				lineSegments->pointArray[lineSegments->count][0].y = (float)curve->c[i][1].y;
				lineSegments->pointArray[lineSegments->count][1].x = (float)curve->c[i][2].x;
				lineSegments->pointArray[lineSegments->count][1].y = (float)curve->c[i][2].y;
				(lineSegments->count)++;

				lineSegments->flag[lineSegments->count] = 0;
				lineSegments->pointArray[lineSegments->count][0].x = (float)curve->c[i][2].x;
				lineSegments->pointArray[lineSegments->count][0].y = (float)curve->c[i][2].y;
				if(i == curve->n-1) //最后一个曲线片段的下一个拐角线是第一个拐角线
				{
					lineSegments->pointArray[lineSegments->count][1].x = (float)curve->c[0][1].x;
					lineSegments->pointArray[lineSegments->count][1].y = (float)curve->c[0][1].y;
				}
				else
				{
					lineSegments->pointArray[lineSegments->count][1].x = (float)curve->c[i+1][1].x;
					lineSegments->pointArray[lineSegments->count][1].y = (float)curve->c[i+1][1].y;
				}
				(lineSegments->count)++;

				//判断该次循环存储的两个直线片段是否能构成一条长直线
				if(mergeLineJudge(&(lineSegments->pointArray[lineSegments->count-2][0]), &(lineSegments->pointArray[lineSegments->count-2][1]), &(lineSegments->pointArray[lineSegments->count-1][0]), &(lineSegments->pointArray[lineSegments->count-1][1]), (float)(M_PI/ANGLE_THRESHOLD), (float)DISTANCE_THRESHOLD))
				{
					CvPoint2D32f* temp = mergeLine(&(lineSegments->pointArray[lineSegments->count-2][0]), &(lineSegments->pointArray[lineSegments->count-2][1]), &(lineSegments->pointArray[lineSegments->count-1][0]), &(lineSegments->pointArray[lineSegments->count-1][1]));
					lineSegments->pointArray[lineSegments->count-2][0] = temp[0];
					lineSegments->pointArray[lineSegments->count-2][1] = temp[1];
					lineSegments->flag[lineSegments->count-1] = 1;
				}
			}
		}
		pNext = pNext->next;
	}
}