Exemplo n.º 1
0
void distinguish(Target *obj, VideoCopy* image,int tX,int tY,ColorBoundary color_B)
{
  int minY = tY;
  int minX = tX;
  int x,y;
  int count = 0;
  int num = minX;
  
  for(x=minX;x<MAX_X;x++){
	for(y=0;y<MAX_Y;y++){
		HSV hsv = ycbcr2HSV(image, x, y);
		
		if(isColor(hsv, color_B)){
			count++;
			
			if(count>NOISE_COUNT){
				
				num=x;
				minY = min(minY, y - NOISE_COUNT);
				
				break;
			}
		}
		
		else
			count = 0;
	}
  }
  obj->start_x = minX;
  obj->end_x = num;
  obj->x_point = (num+minX)/2;
  obj->y_point = minY;
  printf("obj.x : %d, obj.y : %d, flag : %d\nstart_x : %d, end_x : %d\n",obj->x_point,obj->y_point, obj->flag, obj->start_x, obj->end_x);
}
Exemplo n.º 2
0
Target findZone(VideoCopy *image,Target obj)
{
	int x, y;
	int count;
	
	ColorBoundary color_B = classifyObject(obj.flag);
	Target zone = {0, 0, 0, 0, 0};

	
	for(x=1;x<MAX_X;x++){
	  count=0;
	  for(y=MAX_Y/3;y<MAX_Y;y++){

		HSV hsv = ycbcr2HSV(image, x, y);

     		if(isColor(hsv, color_B)){
	   			 count++;
	  		  
			if(count>NOISE_COUNT){ 
				zone.flag = obj.flag;
				distinguish(&zone, image,x,y,color_B);
//				printf("x : %d, y : %d, flag : %d\n", zone.x_point, zone.y_point, zone.flag);
				return zone;
			}
		}
		else
		  count=0;
	  }
	}
	//TODO fail case
	printf("zone not fount\n");
	return zone;
}
Exemplo n.º 3
0
int toleranceSearch(VideoCopy *image, Target *obj, ColorBoundary color_B)
{
	int x, y;
	int start,end;
	int count = 0;
	int past_y = obj->y_point;
	int flag = 0;
	
//	printf("start : %d, end : %d\n", obj->start_x, obj->end_x);   
	
	start = obj->start_x-tolerance < 1 ? 1 : obj->start_x-tolerance;
	end = obj->end_x+tolerance > MAX_X ? MAX_X : obj->end_x+tolerance;

	printf("start : %d, end : %d\n", start, end);    
	
	for(x=start;x<end;x++){

		for(y=1;y<MAX_Y;y++){
			HSV hsv = ycbcr2HSV(image, x, y);

			if(isColor(hsv,color_B)){
				count++;

				if(count>NOISE_COUNT){
					if(flag==0){
						obj->start_x = x;
						flag=1;
					} 
					else 
					    obj->end_x = x;
					
					obj->y_point = min(y,obj->y_point);
					break;
				} 
			} else count = 0;
		}
	}
	
	obj->x_point = (obj->start_x + obj->end_x) /2;
/*	
	if(obj->flag == MILK)	// case milk, 위치 보정
	{ 
	    HSV hsv = ycbcr2HSV(image, obj->x_point, obj->y_point+20);
	    if(!isColor(hsv, green_B))
	      flag = 0;
	} 
*/	
	if(flag==0){
	  printf("flag == 0, in toleranceSearch \n");
	    
	  if(past_y < 50)
	    return 0;
	  
	//  obj->flag = 0;
	  return -1; 
	}
	
	return 1;
}
Exemplo n.º 4
0
bool EKGImageP::isblack(QColor color)
{
    if(isColor(color) > 100)
        return false;
    if(color.red() > 150 || color.blue() > 150 || color.green() >150)
        return false;
    return true;
}
Exemplo n.º 5
0
bool TzEllipse::isColor2(sf::Sprite carte,sf::Color color){

    bool* tab = new bool[8];
    bool res = false;

    tab = isColor(carte,color);

    for(int i = 0; i< 8; i++){
        res = res || tab[i];
    }

    return res;

}
Exemplo n.º 6
0
Target findTarget(VideoCopy *image, int object_Flag) {
  int x,y;
  int countRed,countGreen, countBlue;
  int count = 0;
  Target obj;
  
  obj.flag=0;
  obj.x_point=0;
  obj.y_point=0;
  
  ColorBoundary color_B = classifyObject(object_Flag);
  
  for(x=1;x<MAX_X;x++){
//    countRed=0; countGreen=0; countBlue=0;
    count = 0;
    for(y=1;y<MAX_Y;y++){

	  HSV hsv = ycbcr2HSV(image, x, y);

      if(isColor(hsv, color_B)){	// 파랑이라면
	    count++;
	    //countBlue++;
		if(count>NOISE_COUNT){ 
			obj.flag = object_Flag;
			distinguish(&obj, image,x,y,color_B);
			return obj;
		}
      }
/*      
      else if(isColor(hsv, green_B)){
	    countGreen++;
	    
		if(countGreen>NOISE_COUNT){
			obj.flag = MILK;
			distinguish(&obj, image,x, y, green_B);
			return obj;
		}
      }
*/      
      else
	count = 0;
//	countRed = countGreen = countBlue = 0;
	    
    }
  }

  printf("not found\n");
  return obj;
}
Exemplo n.º 7
0
int EKGImageP::getRow(int row)
{
    //Mohasbe Darsad pixel haye rangi dar satr i
    double darsad;
    double width = 0;
    for(int i = 0 ; i < scanImage.width() ; i++)
    {
        if(isColor(QColor(scanImage.pixel(i,row))) > 50)
        {
            width++;
        }
    }
    darsad = width / scanImage.width();
    darsad *= 100;
    return darsad;
}
Exemplo n.º 8
0
Target refind(VideoCopy *image, int t_Flag, int x_point) {
  int x,y;
  int count;
  Target obj;
  
  ColorBoundary color_B = classifyObject(t_Flag);
  
  obj.flag = 0;
  obj.x_point = 0;
  obj.y_point = 0;
  
  for(x=x_point;x<MAX_X;x++){
    count = 0;
    for(y=1;y<MAX_Y;y++){

	  HSV hsv = ycbcr2HSV(image, x, y);

	  if(isColor(hsv, color_B)){	// 빨강이라면
		count++;
	    
		if(count>NOISE_COUNT){ 
			obj.flag = t_Flag;
			distinguish(&obj, image,x,y,red_B);
			return obj;
		}
	  }
 
	  else
		count= 0;
	    
    }
  }

  printf("not found\n");
  return obj;
}
void EnemyMinionManager::validateMinionBars(ImageData* imageData, std::vector<Minion*>* detectedMinionBars) {
      const float coloredPixelPrecision = 0.96; //0.97
    const float overalImagePrecision = 0.96; //0.97
    const float minionHealthMatch = 0.80; //0.87
    //Remove duplicates
    for (int i = 0; i < detectedMinionBars->size(); i++) {
        Minion* minion = (*detectedMinionBars)[i];
        int detectedCorners = 1;
        for (int j = 0; j < detectedMinionBars->size(); j++) {
            if (j != i) {
                Minion* minion2 = (*detectedMinionBars)[j];
                if (minion2->topLeft.x == minion->topLeft.x && minion->topLeft.y == minion2-> topLeft.y) {
                    detectedMinionBars->erase(detectedMinionBars->begin() + j);
                    j--;
                    if (minion2->detectedBottomLeft) minion->detectedBottomLeft = true;
                    if (minion2->detectedBottomRight) minion->detectedBottomRight = true;
                    if (minion2->detectedTopLeft) minion->detectedTopLeft = true;
                    if (minion2->detectedTopRight) minion->detectedTopRight = true;
                    if (minion2->health > minion->health) minion->health = minion2->health;
                    if (minion2->lowestPercentageMatch < minion->lowestPercentageMatch) minion->lowestPercentageMatch = minion2->lowestPercentageMatch;
                    detectedCorners++;
                }
            }
        }
        if (detectedCorners < 2) {
            detectedMinionBars->erase(detectedMinionBars->begin() + i);
            i--;
        }
        minion->characterCenter.x = minion->topLeft.x+30; minion->characterCenter.y = minion->topLeft.y+32;
    }

    //Detect health
    for (int i = 0; i < detectedMinionBars->size(); i++) {
        Minion* minion = (*detectedMinionBars)[i];
        if (minion->health == 0) {
            for (int x = 61; x >= 0; x--) {
                for (int y = 0; y < healthSegmentImageData.imageHeight; y++) {
                    if (x + minion->topLeft.x >= 0 && x + minion->topLeft.x < imageData->imageWidth &&
                        y + minion->topLeft.y >= 0 && y + minion->topLeft.y < imageData->imageHeight) {
                        uint8_t* healthBarColor = getPixel2(&healthSegmentImageData, 0, y);
                        uint8_t*  p = getPixel2(imageData, x + minion->topLeft.x, y + minion->topLeft.y);
                        if (getColorPercentage(healthBarColor, p) >= minionHealthMatch) {
                            minion->health = (float)x / 61 * 100;
                            y = healthSegmentImageData.imageHeight + 1;
                            x = -1;
                        }
                    }
                }
            }
        }
        if (minion->health == 0) { //Not a minion
            detectedMinionBars->erase(detectedMinionBars->begin() + i);
            i--;
        }
    }
    
    //Detect if ward
    //Ward is 193, 193, 193
    for (int i = 0; i < detectedMinionBars->size(); i++) {
        Minion* minion = (*detectedMinionBars)[i];
        bool isWard = false;
        for (int x = 61; x >= 0; x--) {
            for (int yOffset = -3; yOffset <= 1; yOffset++) {
                if (x + minion->topLeft.x >= 0 && x + minion->topLeft.x < imageData->imageWidth &&
                    yOffset + minion->topLeft.y >= 0 && yOffset + minion->topLeft.y < imageData->imageHeight) {
                    uint8_t*  p = getPixel2(imageData, x + minion->topLeft.x, yOffset + minion->topLeft.y);
                    if (isColor(p, 220, 220, 220, 45)) {
                        isWard = true;
                        x = -1;
                        yOffset = 4;
                    }
                }
            }
        }
        if (isWard) {
            detectedMinionBars->erase(detectedMinionBars->begin() + i);
            i--;
        }
    }
}
Exemplo n.º 10
0
int toleranceZoneSearch(VideoCopy *image, Target *obj, ColorBoundary color_B, int * zoneCnt)
{
	int x, y;
	int start,end;
	int count = 0;
	int past_y = obj->y_point;
	int flag = 0;
	
//	printf("start : %d, end : %d\n", obj->start_x, obj->end_x);   
	
	start = obj->start_x-tolerance < 1 ? 1 : obj->start_x-tolerance;
	end = obj->end_x+tolerance > MAX_X ? MAX_X : obj->end_x+tolerance;

	printf("start : %d, end : %d\n", start, end);    
//	printf("obj y point : %d\n", obj->y_point);
	for(x=start;x<end;x++){

		for(y=20;y<MAX_Y;y++){
			HSV hsv = ycbcr2HSV(image, x, y);

			if(isColor(hsv,color_B)){
				count++;

				if(count>NOISE_COUNT){
					if(flag==0){
						obj->start_x = x;
						flag=1;
					} else obj->end_x = x;
					obj->y_point = min(y,obj->y_point);
					
					break;
				} 
			} else count = 0;
		}
	}
	
	obj->x_point = (obj->start_x + obj->end_x) /2;
/*
	// stop Flag
	if(flag ==1)
	{
	    x = obj->x_point;
	    
	    for(y = MAX_Y -1; y>1 ;y--)
	    {
		HSV hsv = ycbcr2HSV(image, x, y);
		
		if(isColor(hsv, color_B))
		{
		    if(y < 100)	// 경험적으로 이정도 수치면 도착지점 바롤 앞에서 멈춤
		    {
		      *zoneCnt++;
		      
		      if(*zoneCnt > 5)
			flag = 0;
		      
		      printf("y < 95, y = %d\n", y);
		    }
		    break;
		}
	    }
	 
	}
*/	printf("y min : %d\n", obj->y_point);
	if(obj->y_point < 40){
	  *zoneCnt++;
	  if(*zoneCnt > 3)
	    flag = 0;
	}
	
	if(flag==0){
	  printf("flag == 0, in toleranceSearch \n");
	    
	  if(past_y < 50)
	    return 0;
	  
	//  obj->flag = 0;
	  return -1; 
	}
	
	return 1;
}
Exemplo n.º 11
0
void show_threshold( IMAGE_CONTEXT *image_ctx, uchar **frame, uchar thres[3][256], int color, int bf, int bc )
{
    XImage *xImage1 = image_ctx->xImage;
    XEvent event;
	uchar Y, U, V;
	int pix_c = 0;
	bool col;
	int by_s, by_e, bx_s, bx_e, ys, ye, us, ue, vs, ve;

	uchar *imageLine1 = (uchar*) xImage1 -> data;


    for( int i = 0; i < g_height; i++ ) {
	    for( int j = 0; j < 3*g_width; j += 3 ) {

            Y = frame[i][ j + 0 ];
            U = frame[i][ j + 1 ];
            V = frame[i][ j + 2 ];

            col = isColor( thres, Y, U, V, color );

            if( col ) for(int i=0; i<4; i++) imageLine1[ 4*pix_c + i ] = 255;
            else for(int i=0; i<4; i++) imageLine1[ 4*pix_c + i ] = 0;


            pix_c++;
	    }
	}


	image_put( image_ctx );



	if ( XPending( image_ctx->display ) > 0 ) {

	    XNextEvent( image_ctx->display, &event );

	    if( event.type == KeyPress ) {
	        memcpy( thres, last_thres, 768 );
	    }

	    if( event.type == ButtonPress ) {

            memcpy( last_thres, thres, 768 );

            by_s = 0; by_e = g_height; bx_s = 0; bx_e = g_width;

            if( event.xbutton.y - bf + 1 >= 0 ) by_s = event.xbutton.y - bf + 1;
            if( event.xbutton.y + bf <= g_height ) by_e = event.xbutton.y + bf;
            if( event.xbutton.x - bf + 1 >= 0 ) bx_s = event.xbutton.x - bf + 1;
            if( event.xbutton.x + bf <= g_width ) bx_e = event.xbutton.x + bf;

            for( int i = by_s; i < by_e; i++ ) for( int j = bx_s; j < bx_e; j++ ) {

                Y = frame[i][ 3*j + 0 ];
                U = frame[i][ 3*j + 1 ];
                V = frame[i][ 3*j + 2 ];

                ys = 0;
                ye = 256;
                us = 0;
                ue = 256;
                vs = 0;
                ve = 256;
                if( Y - bc + 1 >= 0 ) ys = Y - bc + 1;
                if( Y + bc <= 256 ) ye = Y + bc;
                if( U - bc + 1 >= 0 ) us = U - bc + 1;
                if( U + bc <= 256 ) ue = U + bc;
                if( V - bc + 1 >= 0 ) vs = V - bc + 1;
                if( V + bc <= 256 ) ve = V + bc;


                for( int k = ys; k < ye; k++ ) thres[0][k] &= ~( 1 << color );
                for( int k = us; k < ue; k++ ) thres[1][k] &= ~( 1 << color );
                for( int k = vs; k < ve; k++ ) thres[2][k] &= ~( 1 << color );
            }
	    }
	}
}
Exemplo n.º 12
0
// Print HSV Color Matrix
void findObjectColor(int interval) {
	
	int first_Flag = 1;
	ColorBoundary color_B;
	int color_Type = 0;
	while(1){
	    HSV hsv;
	    int i, j;
	    int count=0;		
	    int index=0;
    //	vidbuf = camera_get_frame(fdCamera);
    //	usleep(3000000); // delay 3sec
    //	camera_release_frame(fdCamera, vidbuf);
    //	vidbuf = camera_get_frame(fdCamera);

	    
	    
	    if(first_Flag == 1)
	    {
		first_Flag = 0;
			printf("Input first boundary Type\n");
			printf("1 : blue, 2 : green, 3:red, 4:yellow\n");
			scanf("%d", &color_Type);		
			if(color_Type == 1)
			{
				color_B.hmin = 190;
				color_B.hmax = 250;
				color_B.smin = 40;
				color_B.smax = 100;
				color_B.vmin = 28;
				color_B.vmax = 100;
			}
			else if(color_Type == 2)
			{
				color_B.hmin = 120;
				color_B.hmax = 168;
				color_B.smin = 47;
				color_B.smax = 100;
				color_B.vmin = 18;
				color_B.vmax = 100;
			}
			else if(color_Type == 3)	
			{
				color_B.hmin = 345;
				color_B.hmax = 15;
				color_B.smin = 45;
				color_B.smax = 100;
				color_B.vmin = 40;
				color_B.vmax = 100;
			}
			else if(color_Type == 4)	
			{
				color_B.hmin = 43;
				color_B.hmax = 76;
				color_B.smin = 40;
				color_B.smax = 100;
				color_B.vmin = 40;
				color_B.vmax = 100;
			}
	    }
	    else
	    {
		char change_Flag;
	      
		printf("value change? y or n\n");
		scanf("%s", &change_Flag);
		
		if(change_Flag == 'y')
		{
		    int whichOne;
		    printf("h : 1, s ; 2, v : 3\ninput : ");\
		    scanf("%d", &whichOne);
		    
		    if(whichOne == 1)
		    {
			printf("H min : ");
			scanf("%d", &(color_B.hmin));
			printf("H max : ");
			scanf("%d", &(color_B.hmax));
		    }
		    else if(whichOne == 2)
		    {
			printf("S min : ");
			scanf("%d", &(color_B.smin));
			printf("S max : ");
			scanf("%d", &(color_B.smax));
		    }
		    else if(whichOne == 3)
		    {
			printf("V min : ");
			scanf("%d", &(color_B.vmin));
			printf("V max : ");
			scanf("%d", &(color_B.vmax));
		    }
		}
		
	    }
	    
	    printf("hmin : %d, hmax : %d\n", color_B.hmin, color_B.hmax); 
	    printf("smin : %d, smax : %d\n", color_B.smin, color_B.smax);
	    printf("vmin : %d, vmax : %d\n", color_B.vmin, color_B.vmax);
	    
	    VideoCopy buf2 = bufCopy;
	    
	    //copy frame to var
	    memcpy(vidbuf_overlay.ycbcr.y, buf2.ycbcr.y,len_vidbuf);
	    memcpy(vidbuf_overlay.ycbcr.cb, buf2.ycbcr.cb,len_vidbuf/2);
	    memcpy(vidbuf_overlay.ycbcr.cr, buf2.ycbcr.cr,len_vidbuf/2);
	    
	    for (i = MAX_Y - (interval / 2); i >= 0; i -= interval) {
		    for (j = MAX_X - (interval / 2); j >= 0; j -= interval) {	
			    hsv = getHSV(&buf2, j, i);
			    index = 320*i + j;			
			    
			    if(isColor(hsv, color_B))
			    {	
			      count++;
			      if(count==1)
				printf("in func\n");
			      
			    obj = 1;			
			    setBoundary(hsv, j, i);
			    
				    vidbuf_overlay.ycbcr.y[index] = 100;	
				    vidbuf_overlay.ycbcr.cb[index/2] = 200;
				    vidbuf_overlay.ycbcr.cr[index/2] = 200;
			    }
		    }
	    }
	    if(obj == 1){
		    printf("Found Milk\n");
		    printf("(minh, maxh, mins, maxs, minv, maxv : (%f, %f, %f, %f, %f, %f)\n", minh, maxh, mins, maxs, minv, maxv);

	    }
	    char tmptmp[100];

	    printf("insert something : ");
	    scanf("%s", tmptmp);
	  
	}
	
}