Esempio n. 1
0
void FaceDetectFilter::processFrame()
{
	QImage image = frameImage();	
	QImage histo = highlightFaces(image);
	
	enqueue(new VideoFrame(histo,m_frame->holdTime()));
}
Esempio n. 2
0
void HistogramFilter::generateHistogram()
{
	if(!m_frame)
		return;
		
	QImage image = frameImage();
	QImage histo = makeHistogram(image);
	
	VideoFrame *frame = new VideoFrame(histo,m_frame->holdTime());
	
	if(m_includeOriginalImage)
		frame->setCaptureTime(m_frame->captureTime());
	
	enqueue(frame);
}
void tst_QVideoFrame::imageDetach()
{
    const uint red = qRgb(255, 0, 0);
    const uint blue = qRgb(0, 0, 255);

    QImage image(8, 8, QImage::Format_RGB32);

    image.fill(red);
    QCOMPARE(image.pixel(4, 4), red);

    QVideoFrame frame(image);

    QVERIFY(frame.map(QAbstractVideoBuffer::ReadWrite));

    QImage frameImage(frame.bits(), 8, 8, frame.bytesPerLine(), QImage::Format_RGB32);

    QCOMPARE(frameImage.pixel(4, 4), red);

    frameImage.fill(blue);
    QCOMPARE(frameImage.pixel(4, 4), blue);

    // Original image has detached and is therefore unchanged.
    QCOMPARE(image.pixel(4, 4), red);
}
Esempio n. 4
0
// Loads the next image in the set, deletes the "last image" and
// moves the currently decoded one to last image.
int ISSImages::loadNextImage()
{
	if ( filenames.size() <= 0 )
	{
		printf("ERROR, no files to load\n");
		return -1;
	}

	// Iterate our image safely
	if ( current_image + 1 == filenames.end() )
		current_image = filenames.begin();
	else
		current_image++;

	// Rotate decoded images
	if ( previous_image_surface )
		SDL_FreeSurface(previous_image_surface);
	if ( current_image_surface )
		previous_image_surface = current_image_surface;

	// Begin our load
	std::cout << "Loading image " << *current_image << "...";

	FILE *fp = fopen((*current_image).c_str(), "rb");
	if ( !fp )
	{
		printf("Can't open file.\n");
		return -1;
	}

	// Determine the size of the file for our buffer
	fseek(fp, 0, SEEK_END);
	unsigned long fsize = ftell(fp);
	rewind(fp);

	// Make a memory buffer the size of the image on our heap
	unsigned char *buf = new unsigned char[fsize];

	// Read the file into our buffer
	if ( fread(buf, 1, fsize, fp) != fsize)
	{
		printf("Can't read file.\n");
		return -1;
	}
	fclose(fp);

	// Parse the exif data to get the rotation
	EXIFInfo result;
	ParseEXIF(buf, fsize, result);

	// Create an SDL_RWops since we already have the file loaded, we don't
	// need another buffer with it, we'll load it and create a surface
	// from the buffer already containing the JPEG
	SDL_RWops *file;
	file = SDL_RWFromMem( buf, fsize );
	current_image_surface = IMG_Load_RW( file, 0 );
	SDL_FreeRW(file);

	if ( ! current_image_surface )
	{
		printf("ERROR Loading image!\n");
		return -1;
	}
	delete[] buf;
	printf("done\n");


	// rotate the image if necessary
	// we want to do this before scaling because it will change whether it's
	// scaled to the W or the H to fit our display
	// -----------------------------------------------------------------------------
	int rotation = 0;
	bool mirrored = false;
	switch (result.orientation)
	{
		case 7:
			mirrored = true;
		case 8:
			rotation = 270;
			break;

		case 5:
			mirrored = true;
		case 6:
			rotation = 90;
			break;

		case 4:
			mirrored = true;
		case 3:
			rotation = 180;
			break;

		case 2:
			mirrored = true;
		case 1:
			rotation = 0;
			break;
	}

	if ( mirrored || rotation )
	{
		printf("Rotating image...");
		if ( rotateImage(rotation, mirrored) )
			printf("ERROR Rotating image!\n");
		else
			printf("done\n");
	}

	// scale the image if necessary
	// -----------------------------------------------------------------------------

	int w = current_image_surface->w;
	int h = current_image_surface->h;

	if (w != 800)
	{
		h = (h * 800) / w;
		w = 800;
	}

	if (h > 600)
	{
		w = (w * 600) / h;
		h = 600;
	}

	if ( w != current_image_surface->w || h != current_image_surface->h)
	{
		printf("Scaling image...");
		if ( scaleImage(w, h) )
			printf("ERROR Scaling image!\n");
		else
			printf("done\n");
	}

	// frame the scaled image, if necessary
	// -----------------------------------------------------------------------------

	if ( 800 != current_image_surface->w || 600 != current_image_surface->h)
	{
		printf("Framing image...");
		if ( frameImage(800, 600) )
			printf("ERROR Framing image!\n");
		else
			printf("done\n");
	}

	// return success
	// -----------------------------------------------------------------------------
	return 0;
}
Esempio n. 5
0
wxImage* wxWebcamV4L2::liveImage() const
{
   return frameImage();
}