/*
*@param descriptors: The descriptors of a block
*/
ImageImPro* HOGDetectorGPU::drawBlockHOG(vector<float> descriptors, cv::HOGDescriptor hog){
    int numHistograms = descriptors.size() / hog.nbins;
    cout << "Num histograms: " << numHistograms << endl;
    vector<float> normalized = normalize(descriptors);
    ImageImPro* ptrImage = NULL;
    int cellsPerRow = hog.blockSize.height / hog.cellSize.height;
    int cellsPerCol = hog.blockSize.width / hog.cellSize.width;
    int pixPerCellX = 32;
    int pixPerCellY = 32;
    ImSize size(cellsPerCol * pixPerCellY, cellsPerRow * pixPerCellX);

    ImageImPro* ptrTemp = new ImageImPro_OpenCvImpl( size, ImageImPro_OpenCvImpl::BIT_8_U, 1);
    Mat* ptrHistImage = ptrTemp->getMat();
    delete ptrTemp;
    int currHist = 0;
    for(int row = 0; row < cellsPerRow; ++row){
        for(int col = 0; col < cellsPerCol; ++col){
            vector <float> cellHistogram = getHistogramFromBlockDescriptor(normalized, currHist++, numHistograms, hog.nbins);
            cout << "Current histogram: " << currHist << endl;
            cv::Mat* ptrMat = getHistogramImage(cellHistogram);
            copyMat(*ptrHistImage, *ptrMat, row * pixPerCellX, col * pixPerCellY);
            delete ptrMat;
        }



    }
    ptrImage = new ImageImPro_OpenCvImpl(ptrHistImage);
    return ptrImage;
}
Exemplo n.º 2
0
void aPow(int p, double a[SIZE][SIZE], double x[SIZE][SIZE], int n)
{
  double b[SIZE][SIZE];
  if (p < 0) {
    printf("aPow: Error!\n");
  } else if (p == 0) {
    unitMat(x, n);
  } else {
    copyMat(a, x, n);  /* x <- a */
    while (p > 1) {
      prod(a, x, b, n);
      copyMat(b, x, n);
      p--;
    }
  }
}
Exemplo n.º 3
0
void mulMat(unsigned long long int A[3][3], unsigned long long int B[3][3],int n) {
	int x, y, k;
	unsigned long long int tmp[3][3] = {0};
	for (y = 0; y < n; y++) {
		for (k = 0; k < n; k++) {
			for (x = 0; x < n; x++) {
				tmp[y][k] = (tmp[y][k] + (A[y][x] * B[x][k]) % MOD) % MOD;
			}
		}
	}
	copyMat(tmp,A,n);
}
Exemplo n.º 4
0
 static PyObject* convert(const MatType& mat) {
     typedef typename MatType::Scalar T;
     PyArrayObject* python_array;
     if( MatType::ColsAtCompileTime==1 || MatType::RowsAtCompileTime==1 ) {
         npy_intp shape[1] = { mat.rows()*mat.cols() };
         python_array = PyArrayObject_New(1, shape, NumpyEquivalentType<T>::type_code);
     }
     else {
         npy_intp shape[2] = { mat.rows(), mat.cols() };
         python_array = PyArrayObject_New(2, shape, NumpyEquivalentType<T>::type_code);
     }
     copyMat( (T*)PyArray_DATA(python_array), mat.data(), mat.rows(), mat.cols(), !(MatType::Flags & RowMajor) );
     return (PyObject*)python_array;
 }
Exemplo n.º 5
0
// Use as a subfilter for Smooth
void ac::ImageRandomValues(cv::Mat &frame) {
    if(blend_set == false)
        return;
    cv::Mat reimage;
    int r_x = rand()%(frame.cols-1);
    int r_y = rand()%(frame.rows-1);
    if(r_x < 10)
        r_x = 10;
    if(r_y < 10)
        r_y = 10;
    cv::Size size_val(r_x, r_y);
    cv::resize(blend_image, reimage, size_val);
    copyMat(frame, reimage);
    AddInvert(frame);
}
Exemplo n.º 6
0
/*
Algorithm taken from Matrix Algorithms Vol. II by G.W. Stewart.

This function takes a vector A of order n  and reduces it to Hessenberg form
by Householder transformations.

In the future it may be possible to remove H entirely and do the transformation
in place.

A is an n*n matrix that I am transforming
H is an n*n matrix where I will put the result
Q is an n*n matrix where I will accumulate the transformations
u is a vector of length n for scratch work.
vH is another vector of length n for scratch work
*/
void hessreduce(Complex *A, Complex *H, Complex *Q, Complex *u, Complex *vH, int n)
{
	int k, i, j, l;
	Complex tmp;
	
	if(n < 2)
		return;
	
	//Reduce A
	//H = A
	copyMat(A,H,n,n);
	
	//3. for k = 1 to n-2
	for(k = 0; k < n-2; k++)
	{
		//Generate the Transformation
		//housegen(H[k+1:n,k],u,H[k+1,k])
		housegen(&INDEX(H,n,(k+1),k),u+k+1,&INDEX(H,n,(k+1),k),n-k-1);
		
		//5. Q[k+1:n,k] = u
		copyVect(u+k+1, &INDEX(Q, n, (k+1), k), n-k-1);
		
		//Premultiply the transformation
		//6. vH = uH*H[k+1:n,k+1:n]
		for(i = k+1; i < n; i++)
		{
			vH[i].real = 0.0;
			vH[i].imag = 0.0;
			
			for(j = k+1; j < n; j++)
			{
				tmp = INDEX(H,n,j,i);
				vH[i].real += u[j].real * tmp.real;
				vH[i].real += u[j].imag * tmp.imag;//minus minus for hermitian
				vH[i].imag += u[j].real * tmp.imag;
				vH[i].imag -= u[j].imag * tmp.real;//minus sign is for hermitian
			}
		}
		
		//7. H[k+1:n,k+1:n] = H[k+1:n, k+1:n] - u*vH
		for(i = k+1; i < n; i++)
		{
			for(j = k+1; j < n; j++)
			{
				INDEX(H,n,i,j).real -= u[i].real *vH[j].real;
				INDEX(H,n,i,j).real += u[i].imag *vH[j].imag;
				INDEX(H,n,i,j).imag -= u[i].real *vH[j].imag;
				INDEX(H,n,i,j).imag -= u[i].imag *vH[j].real;
			}
		}
						
		//H[k+2:n,k] = 0
		for(i = k+2; i < n; i++)
		{
			INDEX(H,n,i,k).real = 0.0;
			INDEX(H,n,i,k).imag = 0.0;
		}
		
		//Postmultiply the transformation
		//9. v = H[1:n, k+1:n]*u
		//I will use the variable vH for v (for space).
		for(i = 0; i < n; i++)
		{
			vH[i].real = 0.0;
			vH[i].imag = 0.0;
			for(j = k+1; j < n; j++)
			{
				tmp = INDEX(H,n,i,j);
				vH[i].real += tmp.real * u[j].real;
				vH[i].real -= tmp.imag * u[j].imag;
				vH[i].imag += tmp.real * u[j].imag;
				vH[i].imag += tmp.imag * u[j].real;
			}
		}
		
		//10. H[1:n, k+1:n] = H[1:n,k+1:n] - v*uH
		for(i = 0; i < n; i++)
		{
			for(j = k+1; j < n; j++)
			{
				INDEX(H,n,i,j).real -= vH[i].real * u[j].real;
				INDEX(H,n,i,j).real -= vH[i].imag * u[j].imag;
				INDEX(H,n,i,j).imag += vH[i].real * u[j].imag;
				INDEX(H,n,i,j).imag -= vH[i].imag * u[j].real;
			}
		}
	}//end k
	
	//Accumulate the Transformations
	//12. Q[:,n] = e_n; Q[:,n-1] = e_(n-1)
	for(i = 0; i < n; i++)
	{
		INDEX(Q,n,i,(n-1)).real = 0.0;
		INDEX(Q,n,i,(n-1)).imag = 0.0;
		INDEX(Q,n,i,(n-2)).real = 0.0;
		INDEX(Q,n,i,(n-2)).imag = 0.0;
	}
	INDEX(Q,n,(n-1),(n-1)).real = 1.0;
	INDEX(Q,n,(n-2),(n-2)).real = 1.0;
	
	//13. for k = n-2 to 1 by -1
	for(k = n-3; k >= 0; k--)
	{	
		//14. u = Q[k+1:n,k]
		copyVect(&INDEX(Q,n,(k+1),k), u+k+1, n-(k+1));
		
		//15. vH = uH*Q[k+1:n,k+1:n]//Q[k+1:n,k] = u
		for(i = k+1; i < n; i++)
		{
			vH[i].real = 0.0;
			vH[i].imag = 0.0;
			for(j = k+1; j < n; j++)
			{
				tmp.real = u[j].real;
				tmp.imag = -u[j].imag;
				tmp = complexMult(tmp, INDEX(Q, n, j, i));
				vH[i].real += tmp.real;
				vH[i].imag += tmp.imag;
			}
		}
		
		//16. Q[k+1:n, k+1:n] = Q[k+1:n, k+1:n] -u*vH
		for(i = k+1; i < n; i++)
		{
			for(j = k+1; j < n; j++)
			{
				tmp = complexMult(u[i],vH[j]);
				INDEX(Q,n,i,j).real -= tmp.real;
				INDEX(Q,n,i,j).imag -= tmp.imag;	
			}
		}
		
		//17. Q[:,k] = e_k
		for(i = 0; i < n; i++)
		{
			INDEX(Q,n,i,k).real = 0.0;
			INDEX(Q,n,i,k).imag = 0.0;
		}
		INDEX(Q,n,k,k).real = 1.0;
		
	}// 18. end for k
}//end hessreduce