Ejemplo n.º 1
0
void Posterize(uchar posterizeFilter, IplImage* frame, IplImage* base)
{
	CvPixelPosition8u posA, posB;
	uchar* pA, *pB;
	CvSize size;
	int x, y;

	size = cvGetSize(frame);

	x = 0; y = 0;
	CV_INIT_PIXEL_POS(posA, (unsigned char*) frame->imageData,
						frame->widthStep, size, x, y, frame->origin);
	CV_INIT_PIXEL_POS(posB, (unsigned char*) base->imageData,
						base->widthStep, size, x, y, base->origin);

	for(y = 0; y < size.height; y++) {
		for(x = 0; x < size.width; x++) {
			pA = CV_MOVE_TO(posA, x, y, 3);
			pB = CV_MOVE_TO(posB, x, y, 3);

			pB[0] = pA[0] & posterizeFilter;
			pB[1] = pA[1] & posterizeFilter;
			pB[2] = pA[2] & posterizeFilter;
		}
	}
}
Ejemplo n.º 2
0
void AlphaBlend(IplImage* srcA, IplImage* srcB, IplImage* alpha, IplImage* dst)
{
	CvPixelPosition8u posA, posB, posC, posD;
	uchar* pA, *pB, *pC, *pD;
	CvSize size;
	int x, y;
	float a, b;

	size = cvGetSize(srcA);

	x = 0; y = 0;
	CV_INIT_PIXEL_POS(posA, (unsigned char*) srcA->imageData,
						srcA->widthStep, size, x, y, srcA->origin);
	CV_INIT_PIXEL_POS(posB, (unsigned char*) srcB->imageData,
						srcB->widthStep, size, x, y, srcB->origin);
	CV_INIT_PIXEL_POS(posC, (unsigned char*) alpha->imageData,
						alpha->widthStep, size, x, y, alpha->origin);
	CV_INIT_PIXEL_POS(posD, (unsigned char*) dst->imageData,
						dst->widthStep, size, x, y, dst->origin);

	for(y = 0; y < size.height; y++) {
		for(x = 0; x < size.width; x++) {
			pA = CV_MOVE_TO(posA, x, y, 3);
			pB = CV_MOVE_TO(posB, x, y, 3);
			pC = CV_MOVE_TO(posC, x, y, 3);
			pD = CV_MOVE_TO(posD, x, y, 3);

			b = pC[0] / 255.0f;
			a = 1.0f - b;
			pD[0] = (uchar) (pA[0] * a + pB[0] * b);
			pD[1] = (uchar) (pA[1] * a + pB[1] * b);
			pD[2] = (uchar) (pA[2] * a + pB[2] * b);
		}
	}
}
Ejemplo n.º 3
0
void CHSVToonEffect::HSVToon(IplImage* frame, IplImage* base)
{
	CvPixelPosition8u posA;
	uchar* pA;
	CvSize size;
	int x, y;
	int v = 2;

	size = cvGetSize(frame);

	cvCvtColor(frame, hsv, CV_BGR2HSV);


	x = 0; y = 0;
	CV_INIT_PIXEL_POS(posA, (unsigned char*) hsv->imageData,
						hsv->widthStep, size, x, y, hsv->origin);

	for(y = 0; y < size.height; y++) {
		for(x = 0; x < size.width; x++) {
			pA = CV_MOVE_TO(posA, x, y, 3);

			if(pA[v] >= 255 * 0.8) pA[v] = 255;
			else if(pA[v] >= 255 * 0.5) pA[v] = 204;
			else if(pA[v] >= 255 * 0.3) pA[v] = 127;
			else pA[v] = 63;
		}
	}

	cvCvtColor(hsv, base, CV_HSV2BGR);
}
Ejemplo n.º 4
0
//指定した色にマスクをかける
void maskRGB(IplImage* src_img, IplImage *dst_img, int rgb_thre[]) {
  int x = 0, y = 0;
  uchar R, G, B;
  uchar *p_src, *p_dst;
  CvPixelPosition8u pos_src, pos_dst;

  IplImage* tmp = cvCreateImage(cvGetSize(src_img), IPL_DEPTH_8U , 3);
  cvCopy(src_img, tmp, NULL);

  CV_INIT_PIXEL_POS(pos_src, (unsigned char *)tmp->imageData,
  		    tmp->widthStep, cvGetSize(tmp), x, y, tmp->origin);
  CV_INIT_PIXEL_POS(pos_dst, (unsigned char *)dst_img->imageData,
		    dst_img->widthStep, cvGetSize(dst_img), x, y, dst_img->origin);

  for( y=0; y < src_img->height; y++) {
    for ( x=0; x < src_img->width; x++) {
      p_src = CV_MOVE_TO(pos_src, x, y, 3);
      p_dst = CV_MOVE_TO(pos_dst, x, y, 3);

      R = p_src[2];
      G = p_src[1];
      B = p_src[0];

      if(rgb_thre[0] <= R && R <= rgb_thre[1] &&
	 rgb_thre[2] <= G && G <= rgb_thre[3] &&
	 rgb_thre[4] <= B && B <= rgb_thre[5]) {
	p_dst[0] = p_src[0];
	p_dst[1] = p_src[1];
	p_dst[2] = p_src[2];
	}
      else {
	p_dst[0] = 0;
	p_dst[1] = 0;
	p_dst[2] = 0;
      }
    }
  }
  cvReleaseImage(&tmp);
}
Ejemplo n.º 5
0
void CHandDrawEffect::Init(CvSize size)
{
	CCVEffect::Init(size);

	X			= 5;
	Y			= 54;
	Z			= 0;
	lineWidth	= 1;
	lineNoise	= 15;
	DARK		= 0.7; //1.0;

	VFlag		= 0;
	hatchingType = 2; //0
	drawMode	= 3;
	patternOffset = 1; //0

	posterizeFilter = 0xD0;

	hsv			= cvCreateImage(size, IPL_DEPTH_8U, 3);  
	grayImage	= cvCreateImage(size, IPL_DEPTH_8U, 1);
	binaryImage	= cvCreateImage(size, IPL_DEPTH_8U, 1);
	imageA		= cvCreateImage(size, IPL_DEPTH_8U, 3);
	imageB		= cvCreateImage(size, IPL_DEPTH_8U, 3);

	CvPixelPosition8u posA;
	uchar* pA;
	uchar m;
	int x = 0, y = 0;

	imageC		= cvCreateImage(size, IPL_DEPTH_8U, 3);
	CV_INIT_PIXEL_POS(posA, (unsigned char*) imageC->imageData,
						imageC->widthStep, size, x, y, imageC->origin);

	imageD		= cvCreateImage(size, IPL_DEPTH_8U, 3);
	imageE		= cvCreateImage(size, IPL_DEPTH_8U, 3);

	for(y = 0; y < size.height; y++) {
		for(x = 0; x < size.width; x++) {
			pA = CV_MOVE_TO(posA, x, y, 3);
			pA[2] = 0x00; //R
			pA[1] = 0xFF; //G
			pA[0] = 0x00; //B
		}
	}


	scanningLine = cvCreateImage(size, IPL_DEPTH_8U, 3);
	CV_INIT_PIXEL_POS(posA, (unsigned char*) scanningLine->imageData,
						scanningLine->widthStep, size, x, y, scanningLine->origin);

	for(y = 0; y < size.height; y++) {
		m = y % 4 ? 255 : 200;
		for(x = 0; x < size.width; x++) {
			pA = CV_MOVE_TO(posA, x, y, 3);
			pA[0] = m;
			pA[1] = m;
			pA[2] = m;
		}
	}

	memStorage0	= cvCreateMemStorage(0);

	char buf[256];
	for(int i = 0; i < PATT_NUM; i++) {
		sprintf(buf, "Data/img/h%d.bmp", i);
		hatching[i] = cvLoadImage(buf);
	}
}