示例#1
0
cv::Mat CMyImageProc::GenSaliencyMap(cv::Mat &img)
{
	cv::Mat saliencyImg;

	std::vector<UINT> temImg;
	for(int i=0; i<img.rows; i++) {
		for(int j=0; j<img.cols; j++) {
			cv::Vec3b &pf = img.at<cv::Vec3b>(i, j);
			UINT rgb = ( (UINT) ( (pf[0] | ((unsigned short)( pf[1] )<<8)) | (((unsigned long) pf[2])<<16) ) );
			temImg.push_back(rgb);
		}
	}
	Saliency ss;
	std::vector<double> salmap;
	ss.GetSaliencyMap(temImg, img.cols, img.rows, salmap);

	saliencyImg = cv::Mat(img.rows, img.cols, CV_8U);
	int n=0;
	for(int i=0; i<img.rows; i++) {
		for(int j=0; j<img.cols; j++, n++) {
			int val = int (salmap[n] + 0.5);
			saliencyImg.at<uchar>(i, j) = (uchar) val;
		}
	}

	return saliencyImg;
}
示例#2
0
// ./Imgs/*.jpg   ./Sal/ 
int main(int argc,char *argv[])
{
	CV_Assert(argc == 3);
	string imgW = argv[1], salDir = argv[2];
	string imgDir, imgExt;
	vecS namesNE;
	CmFile::MkDir(salDir);
	int imgNum = CmFile::GetNamesNE(imgW, namesNE, imgDir, imgExt);

	for (int i = 0; i < imgNum; i++){
		if (CmFile::FilesExist(salDir + namesNE[i] + "_FT.png"))
			continue;


		vector<UINT> img(0);// or UINT* imgBuffer;
		int width(0);
		int height(0);


		PictureHandler picHand;
		picHand.GetPictureBuffer(imgDir + namesNE[i] + imgExt, img, width, height );
		int sz = width*height;

		Saliency sal;
		vector<double> salmap(0);
		sal.GetSaliencyMap(img, width, height, salmap, true);

		vector<UINT> outimg(sz);
		for( int i = 0; i < sz; i++ ){
			int val = int(salmap[i] + 0.5);
			outimg[i] = val << 16 | val << 8 | val;
		}

		picHand.SavePicture(outimg, width, height, namesNE[i], salDir, 0, "_FT");// 0 is for BMP and 1 for JPEG)

		Mat sal1u = imread(salDir + namesNE[i] + "_FT.bmp", CV_LOAD_IMAGE_GRAYSCALE);
		imwrite(salDir + namesNE[i] + "_FT.png", sal1u);
		CmFile::RmFile(salDir + namesNE[i] + "_FT.bmp");
	}
}
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);
}
示例#4
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;
	
}