void MotionDetection::SaliencyDetection(Mat frame, Mat mask)
{
  Saliency saliency;
  Mat frame_copy = frame.clone();
  //get saliency
  //Mat dstImg(frame.rows,frame.cols,frame.type());
  //IplImage* frame2 = cvCloneImage(&(IplImage)frame);
  //IplImage* cvGetImage( const CvArr* arr, IplImage* image_header );   
  IplImage  frame2 = frame_copy;
  IplImage* frame3 = &frame2;
  IplImage* dstImg = cvCreateImage(cvSize(frame3->width, frame3->height), 8, 1);
  //convert color
  cvThreshold(frame3, frame3, 200, 255, CV_THRESH_BINARY);
  saliency.calcIntensityChannel(frame3, dstImg);
  // printf("dstImg->width: %d dstImg->height %d dstImg->depth %d dstImg->nChannels %d \n", dstImg->width, dstImg->height ,
  //       dstImg->depth , dstImg->nChannels);

  Mat dstImgMat(dstImg,true);
  for(int i = 0 ; i < dstImgMat.cols; i++)
  {
    for(int j = 0; j < dstImgMat.rows; j++)
    {
      Point p(i,j);
      // //if(dstImgMat.at<uchar>(p) > 127){
      //  mask.at<uchar>(p) += 1; 
      // //}
      //   //dstImgMat.at<uchar>(p) = 255;
      //     //
      //     //segmentation fau
      if(dstImgMat.at<uchar>(p) > 127){
          mask.at<uchar>(p) += mask_add_step;
      }
    }
  }
  //cvReleaseImage(&dstImg);
}
예제 #2
0
//imagenes de color
//acuerdate de cambiar la cantidad de caracteristicas a 12
void makeFrgb(const Mat& img, vector<Mat>& F, config_SystemParameter *param){
	CV_Assert(F.size() == param->numFeature);
	CV_Assert(img.channels() == 3);
	//por el momento, deberia ser borrado este assert
	CV_Assert(param->numFeature == 12);
	
	Mat greyImg,greyAux;
	cvtColor(img, greyImg, CV_RGB2GRAY);
	equalizeHist(greyImg, greyAux );
	greyAux.convertTo(greyImg, CV_32F);
	//greyAux.release();
	
	
	vector<Mat> Mrgb;
	split(img, Mrgb);
	
	//INICIALIZANDO VECTOR CON VALORES FLOATS
	for (int i=0; i<param->numFeature; i++) {
		F[i]  = Mat(Mrgb[2].rows,Mrgb[2].cols,CV_32F);
	}
	
	//CREANDO MATRICES X E Y
	for(int i = 0; i < F[0].rows; i++)
	{
		float* MatF0i = F[0].ptr<float>(i);
		float* MatF1i = F[1].ptr<float>(i);
		
		for(int j = 0; j < F[0].cols; j++){
			MatF0i[j] = (float)j;
			MatF1i[j] = (float)i;
		}
	}
	
	//MATRICES RGB PERO CON FORMATO FLOAT
	
	greyAux.release();
	Mrgb[0].convertTo(F[2], CV_32F);
	equalizeHist(Mrgb[1], greyAux );
	greyAux.convertTo(F[3], CV_32F);
	greyAux.release();
	equalizeHist(Mrgb[2], greyAux );
	greyAux.convertTo(F[4], CV_32F);
	
	
	//PRIMERA DERIVADA
	cv::Ptr<FilterEngine> Fc = createDerivFilter(F[2].type(), CV_32F, 1, 0, 3);
	Fc->apply(greyImg,F[5], cv::Rect(0,0,-1,-1),cv::Point(0,0));
	F[5] = abs(F[5]);
	
	Fc = createDerivFilter(F[2].type(), CV_32F, 0, 1, 3);
	Fc->apply(greyImg,F[6], cv::Rect(0,0,-1,-1),cv::Point(0,0));
	F[6] = abs(F[6]);
	
	//MAGNITUD DE LA DERIVADA
	magnitude(F[5], F[6], F[7]);
	
	//SEGUNDA DERIVADA
	Fc = createDerivFilter(F[2].type(), CV_32F, 2, 0, 3);
	Fc->apply(greyImg,F[8], cv::Rect(0,0,-1,-1),cv::Point(0,0));
	F[8] = abs(F[8]);
	
	Fc = createDerivFilter(F[2].type(), CV_32F, 0, 2, 3);
	Fc->apply(greyImg,F[9], cv::Rect(0,0,-1,-1),cv::Point(0,0));
	F[9] = abs(F[9]);
	
	//PHASE DE LA PRIMERA DERIVADA EN X E Y
	phase(F[5], F[6], F[10]);
	
	//SILENCY
	
	IplImage srcImg, *dstImg;
	
	srcImg = IplImage(greyAux);
	dstImg = cvCreateImage(cvSize(srcImg.width, srcImg.height), 8, 1);
	Saliency *saliency = new Saliency;
	
	saliency->calcIntensityChannel(&srcImg, dstImg);
	
	F[11] = Mat(dstImg);
	Mat aux(Mrgb[2].rows,Mrgb[2].cols,CV_32F);
	F[11].convertTo(aux,F[9].type());
	F[11] = aux;
	
	greyAux.release();
	greyImg.release();
	delete saliency;
	
}