Ejemplo n.º 1
0
void MainWindow::startProcessing()
{
    connect(controller->processingThread, SIGNAL(newProcessedFrame(QImage)), this, SLOT(updateVideoLabel(QImage)));
    connect(controller->processingThread->tracker_, SIGNAL(newCorrelationImage(QImage)), this, SLOT(updateOutputLabel(QImage)));
    connect(controller->processingThread->tracker_, SIGNAL(newFilterImage(QImage)), this, SLOT(updateFilterLabel(QImage)));
    connect(controller->processingThread->tracker_, SIGNAL(newInputImage(QImage)), this, SLOT(updateInputLabel(QImage)));

    // enable play btn and set the icon to pause
    ui->playButton->setEnabled(true);
    ui->playButton->setIcon(QIcon(":/pauseIcon"));
    // enable the menu option for selecting the target
    ui->actionSelect_target->setEnabled(true);
}
Ejemplo n.º 2
0
void WorkerThread::createNewFilter()
{
	// Free GPU memory from current filter and CUFFT
	cudaFree(_gabor_data);
	cudaFree(_gpu_image_0);
	cudaFree(_gpu_image_1);
	cufftDestroy(_fft_plan);

	float* gaussian_data;
	cudaMalloc((void**)&gaussian_data, sizeof(float) * _filter_pixels);
	int2 gaussian_size;
	gaussian_size.x = _filter_size;
	gaussian_size.y = _filter_size;
	int2 gaussian_center;
	gaussian_center.x = _filter_size / 2;
	gaussian_center.y = _filter_size / 2;
	gaussian(gaussian_data, _new_theta, _new_sigma, 1.0, gaussian_center, gaussian_size);
	
	float* harmonic_data;
	cudaMalloc((void**)&harmonic_data, sizeof(float) * _filter_pixels * 2);
	int2 harmonic_size;
	harmonic_size.x = _filter_size;
	harmonic_size.y = _filter_size;
	int2 harmonic_center;
	harmonic_center.x = _filter_size / 2;
	harmonic_center.y = _filter_size / 2;
	harmonic(harmonic_data, _new_theta, _new_lambda, _new_psi, harmonic_center, harmonic_size);
	float* host_harmonic = new float[_filter_size * _filter_size * 2];
	
	cudaMalloc((void**)&_gabor_data, sizeof(float) * _filter_pixels * 2);
	int2 gabor_size;
	gabor_size.x = _filter_size;
	gabor_size.y = _filter_size;
	int2 gabor_center;
	gabor_center.x = _filter_size / 2;
	gabor_center.y = _filter_size / 2;
	multiplyRealComplex(gaussian_data, harmonic_data, _gabor_data, _filter_size * _filter_size);
	float* host_gabor_data = new float[_filter_pixels * 2];
	cudaMemcpy(host_gabor_data,
		_gabor_data,
		sizeof(float) * _filter_pixels * 2,
		cudaMemcpyDeviceToHost);

	//pad the filter
	{
		float* data = host_gabor_data;
		float* target = _filter_image;
		memset(target, 0, sizeof(float) * _padded_pixels * 2);
		int padded_stride = 2 * _padded_size;
		int target_stride = 2 * _target_size;
		for (int i = 0; i < _target_size; ++i)
		{
			memcpy(target, data, sizeof(float) * target_stride);
			target += padded_stride;
			data += target_stride;
		}
	}

	// Copy gabor data into member for texture creation
	_filter_image_mutex.lock();
	memcpy(_host_gabor_data, host_gabor_data, sizeof(float) * _filter_pixels * 2);
	_filter_image_mutex.unlock();
	
	cudaFree(_gabor_data);
	
	cudaMalloc((void**)&_gabor_data, sizeof(float) * _padded_pixels * 2);
	cudaMalloc((void**)&_gpu_image_0, sizeof(float) * _padded_pixels * 2);
	cudaMalloc((void**)&_gpu_image_1, sizeof(float) * _padded_pixels * 2);
	cudaMemcpy(_gabor_data,
		_filter_image,
		sizeof(float) * _padded_pixels * 2,
		cudaMemcpyHostToDevice);

	cufftPlan2d(&_fft_plan, _padded_size, _padded_size, CUFFT_C2C);
	cufftExecC2C(_fft_plan,
		(cufftComplex*)(_gabor_data),
		(cufftComplex*)(_gabor_data),
		CUFFT_FORWARD);
	cudaMemcpy(_filter_image,
		_gabor_data,
		sizeof(float) * _padded_pixels * 2,
		cudaMemcpyDeviceToHost);

	// Free temporary GPU memory used for creation of filter
	cudaFree(gaussian_data);
	cudaFree(harmonic_data);

	delete host_harmonic;
	delete host_gabor_data;

	_should_create_new_filter = false;

	emit newFilterImage();
}
Ejemplo n.º 3
0
void WorkerThread::createInitialFilter()
{
	float* gaussian_data;
	cudaMalloc((void**)&gaussian_data, sizeof(float) * _filter_pixels);
	int2 gaussian_size;
	gaussian_size.x = _filter_size;
	gaussian_size.y = _filter_size;
	int2 gaussian_center;
	gaussian_center.x = _filter_size / 2;
	gaussian_center.y = _filter_size / 2;
	gaussian(gaussian_data, 0.0, _sigma, 1.0, gaussian_center, gaussian_size);
	
	float* harmonic_data;
	cudaMalloc((void**)&harmonic_data, sizeof(float) * _filter_pixels * 2);
	int2 harmonic_size;
	harmonic_size.x = _filter_size;
	harmonic_size.y = _filter_size;
	int2 harmonic_center;
	harmonic_center.x = _filter_size / 2;
	harmonic_center.y = _filter_size / 2;
	harmonic(harmonic_data, 0, _lambda, 0.0, harmonic_center, harmonic_size);
	float* host_harmonic = new float[_filter_size * _filter_size * 2];
	
	cudaMalloc((void**)&_gabor_data, sizeof(float) * _filter_pixels * 2);
	int2 gabor_size;
	gabor_size.x = _filter_size;
	gabor_size.y = _filter_size;
	int2 gabor_center;
	gabor_center.x = _filter_size / 2;
	gabor_center.y = _filter_size / 2;
	multiplyRealComplex(gaussian_data, harmonic_data, _gabor_data, _filter_size * _filter_size);
	float* host_gabor_data = new float[_filter_pixels * 2];
	cudaMemcpy(host_gabor_data,
		_gabor_data,
		sizeof(float) * _filter_pixels * 2,
		cudaMemcpyDeviceToHost);

	//pad the filter
	{
		float* data = host_gabor_data;
		float* target = _filter_image;
		memset(target, 0, sizeof(float) * _padded_pixels * 2);
		int padded_stride = 2 * _padded_size;
		int target_stride = 2 * _target_size;
		for (int i = 0; i < _target_size; ++i)
		{
			memcpy(target, data, sizeof(float) * target_stride);
			target += padded_stride;
			data += target_stride;
		}
	}

	// Copy gabor data into member for texture creation
	_filter_image_mutex.lock();
	memcpy(_host_gabor_data, host_gabor_data, sizeof(float) * _filter_pixels * 2);
	_filter_image_mutex.unlock();
	
	cudaFree(_gabor_data);
	
	cudaMalloc((void**)&_gabor_data, sizeof(float) * _padded_pixels * 2);
	cudaMalloc((void**)&_gpu_image_0, sizeof(float) * _padded_pixels * 2);
	cudaMalloc((void**)&_gpu_image_1, sizeof(float) * _padded_pixels * 2);
	cudaMemcpy(_gabor_data,
		_filter_image,
		sizeof(float) * _padded_pixels * 2,
		cudaMemcpyHostToDevice);

	cufftPlan2d(&_fft_plan, _padded_size, _padded_size, CUFFT_C2C);
	cufftExecC2C(_fft_plan,
		(cufftComplex*)(_gabor_data),
		(cufftComplex*)(_gabor_data),
		CUFFT_FORWARD);
	cudaMemcpy(_filter_image,
		_gabor_data,
		sizeof(float) * _padded_pixels * 2,
		cudaMemcpyDeviceToHost);

	emit newFilterImage();
}