Beispiel #1
0
void Animation::drawFrameOnPicture(int32 frame, int16 xx, int16 yy) {
	debugC(1, kDebugAnim, "drawFrameOnPicture(%d, %d, %d)", frame, xx, yy);
	if (frame < 0)
		frame = 0;

	if (frame >= _numFrames)
		frame = _numFrames - 1;

	if (_numFrames == 0)
		return;

	if (_frames[frame]._ref != -1)
		frame = _frames[frame]._ref;

	int16 rectX = _frames[frame]._x2 - _frames[frame]._x1;
	int16 rectY = _frames[frame]._y2 - _frames[frame]._y1;

	Picture *pic = _vm->getPicture();

	if ((xx + _x1 + _frames[frame]._x1 < 0) || (yy + _y1 + _frames[frame]._y1 < 0))
		return;

	if (rectX + xx + _x1 + _frames[frame]._x1 >= pic->getWidth())
		rectX = pic->getWidth() - xx - _x1 - _frames[frame]._x1;

	if (rectX < 0)
		return;

	if (rectY + yy + _y1 + _frames[frame]._y1 >= pic->getHeight())
		rectY = pic->getHeight() - yy - _y1 - _frames[frame]._y1;

	if (rectY < 0)
		return;

	int32 destPitch = pic->getWidth();
	uint8 *c = _frames[frame]._data;
	uint8 *curRow = (uint8 *)pic->getDataPtr() + (yy + _frames[frame]._y1 + _y1) * destPitch + (xx + _x1 + _frames[frame]._x1);
	for (int16 y = 0; y < rectY; y++) {
		unsigned char *cur = curRow;
		for (int16 x = 0; x < rectX; x++) {
			if (*c)
				*cur = *c;
			c++;
			cur++;
		}
		curRow += destPitch;
	}
}
void GfxGlEngine::drawPicture(const Picture &picture, const int dx, const int dy, Rect* clipRect)
{
   GLuint aTextureID = picture.getGlTextureID();
   float x0 = (float)( dx+picture.getOffset().getX());
   float x1 = x0+picture.getWidth();
   float y0 = (float)(dy-picture.getOffset().getY());
   float y1 = y0+picture.getHeight();


   // Bind the texture to which subsequent calls refer to
   glBindTexture( GL_TEXTURE_2D, aTextureID);

   glBegin( GL_QUADS );

   //Bottom-left vertex (corner)
   glTexCoord2i( 0, 0 );
   glVertex2f( x0, y0 );

   //Bottom-right vertex (corner)
   glTexCoord2i( 1, 0 );
   glVertex2f( x1, y0 );

   //Top-right vertex (corner)
   glTexCoord2i( 1, 1 );
   glVertex2f( x1, y1 );

   //Top-left vertex (corner)
   glTexCoord2i( 0, 1 );
   glVertex2f( x0, y1 );

   glEnd();
}
Picture UnStabilizator::nextStep(Picture basePic)
{
	if (basePic.getWidth() == 0) return Picture();

	double angle = dif_lib::randomDoubleSigned(shiftAngle * M_PI / 180.0);
	double* homoData = new double[6];
	homoData[2] = dif_lib::randomDoubleSigned(shiftX);
	homoData[5] = dif_lib::randomDoubleSigned(shiftY);
	homoData[0] = cos(angle);
	homoData[4] = cos(angle);
	homoData[1] = sin(angle);
	homoData[3] = -sin(angle);
	Homography h**o = Homography(Matrix(2,3,sh_ptr_db(homoData)));
	basePic = picConverter.applyHomo(basePic, h**o);
	return basePic;
}
Beispiel #4
0
Picture Picture::operator +(Picture const& pic) const
{
	if (pic.getColors() != this->getColors() || pic.getHeight() != this->getHeight() || pic.getWidth() != this->getWidth()) return Picture(0, 0);
	Picture res = pic.clone();
	for (int c = 0; c < colors; ++c)
	{
		for (int i = 0; i < width; ++i)
		{
			for (int j = 0; j < height; ++j)
			{
				int sum = pic.get(i, j, c);
				sum += get(i, j, c);
				res.at(i, j, c) = (unsigned char) (sum % 256);
			}
		}
	}
	return res;
}
Beispiel #5
0
void Mediator::nextProjStep()
{
	bitmap *bitMap = frameReader.nextFrame();
	Picture basePic(width, height, 3);
	basePic.copyPic(bitMap->data);
	PictureConverter picConv;
	Picture smallPic = picConv.downscale(basePic, 2);
	if (curImage.getWidth() == 0)
	{
		track_data.ml_track_init(smallPic.getPicture().get());
	}
	else
	{
		unsigned char* data = smallPic.getPicture().get();
		track_data.ml_track_track(data);
	}
	curImage = picConv.stretch(smallPic, 2);//basePic.clone();
	Picture rect = curImage.getRectMiddle(bandWidth);
	frameReader.saveFrame(rect.getPictureChar(), rect.getWidth(), rect.getHeight(), 3);
}
Picture MotionDetectorAction::nextStep(Picture pic)
{
	if (pic.getWidth() == 0) return Picture();
	motionDetector->nextStep(pic);
	return motionDetector->getPicByMode();
}
Beispiel #7
0
void Mediator::nextStep()
{
	DWORD tm = GetTickCount();
	prevImage = curImage;
	DWORD tm1 = GetTickCount();

	bitmap *bitMap = frameReader.nextFrame();
	Picture basePic(width, height, 3);
	basePic.copyPic(bitMap->data);

	basePic = picConverter.fixDistortions(converter, basePic);
	Picture smallGreyPic = picConverter.convertColor(basePic);
	if (downscale > 1.05)
	{
		smallGreyPic = picConverter.downscale(smallGreyPic, downscale);
	}
	Picture curImage1 = smallGreyPic;//.getRectMiddle(0);// - gauss.apply(smallGreyPic);/*gauss.apply(smallGreyPic);*/
	Capture_Log::getInstance()->log_write("Preprocess time is %d\n", GetTickCount() - tm1);

	Homography h**o = homoEstimator.getHomography(prevImage.getWidth() != 0 ? prevImage : curImage1, curImage1, stepSize);
	h**o.applyDownscale(1.0 / (double)downscale);

	Homography clearHomo = kalmanHomo.observe(h**o);
	
	
	Matrix clearHomoMatrix = clearHomo.getHomoMatrix3x3();
	Matrix clHomoObr = clearHomoMatrix.obratn();
	Matrix homoMatr = h**o.getHomoMatrix3x3();
	Matrix HnoiseMatr = clHomoObr * homoMatr;

	Capture_Log::getInstance()->log_write("\n\n\n");
	Capture_Log::getInstance()->log_write("Estimated h**o is\n");
	h**o.printLog();

	Capture_Log::getInstance()->log_write("Kalman h**o is\n");
	clearHomo.printLog();

	Capture_Log::getInstance()->log_write("Kalman obratn h**o is\n");
	dif_lib::print(clHomoObr);

	Capture_Log::getInstance()->log_write("Noise h**o is\n");
	dif_lib::print(HnoiseMatr);

//	curHomo = Homography(HnoiseMatr);
	Capture_Log::getInstance()->log_write("Check base h**o is\n");
	dif_lib::print(clearHomoMatrix * HnoiseMatr);
	curHomo.printLog();
	Capture_Log::getInstance()->log_write("\n\n\n");
	
	

/*	Homography homoE = Homography();
	curHomo = homoE * beta1 + h**o * alpha1 + curHomo * (1 - alpha1 - beta1);*/

//	curImage = curImage1;
	curImage = picConverter.applyHomo(curImage1, curHomo);

	if (prevPic.getWidth() == 0)
	{
		prevPic = basePic.clone();
	}
	Gaussian gs(width, height, 2.0);
	if (0 && params.debug && bitMap->data && prevPic.getWidth() > 0)
	{
//		Capture_Log::getInstance()->log_write("Gaussian full time is %d\n", GetTickCount() - tm);
		static int frameId = 0;
		char name1[11] = "filea.jpeg";
		char name2[12] = "fileaa.jpeg";
		name1[4] += frameId;
		name2[4] += frameId;
		frameId++;
/*		Picture pic0 = gs.apply(prevPic);
		Picture pic1 = picConverter.applyHomo(basePic, h**o);
		Picture pic = gs.apply(pic1);
		double dist = tester.imgDistace(pic0.getPictureChar(), pic.getPictureChar(), 3);*/
		frameReader.saveFrame(curImage1.getPictureChar(), smallGreyPic.getWidth(), smallGreyPic.getHeight(), smallGreyPic.getColors(), name1);
/*		frameReader.saveFrame(pic.getPictureChar(), width, height, 3, name2);
		Capture_Log::getInstance()->log_write("Pictures distance is %.2f\n", dist);*/
	}

//	Picture img = gs.apply(basePic);
	tm1 = GetTickCount();
	convImage = picConverter.applyHomo(basePic, curHomo);
	Capture_Log::getInstance()->log_write("H**o time is %d\n", GetTickCount() - tm1);
	tm1 = GetTickCount();
//	convImage = gauss.apply(convImage);
	Capture_Log::getInstance()->log_write("Gauss time is %d\n", GetTickCount() - tm1);

	if (params.debug)
	{
		laplas = basePic.clone();//picConverter.convertGrey(curImage1/* - gs.apply(curImage1)*/, 3);//convImage;// - gs.apply(convImage);
	}
	else
	{
		laplas = convImage;
	}


	tm1 = GetTickCount();
	Picture rect = convImage.getRectMiddle(bandWidth);
	frameReader.saveFrame(rect.getPictureChar(), rect.getWidth(), rect.getHeight(), 3);
	
/*	rect = basePic.getRectMiddle(bandWidth);
	frameReader.saveFrame(rect.getPictureChar(), rect.getWidth(), rect.getHeight(), 3);*/

	Capture_Log::getInstance()->log_write("Save time is %d\n", GetTickCount() - tm1);

//	prevPic = basePic.clone();
	bitmap_release(bitMap);
	Capture_Log::getInstance()->log_write("Step time is %d\n\n\n", GetTickCount() - tm);
}