Exemple #1
0
Mat charProjectFeatures(const Mat& in, int sizeData) {
  const int VERTICAL = 0;
  const int HORIZONTAL = 1;

  SHOW_IMAGE(in, 0);
  // cut the cetner, will afect 5% perices.

  Mat lowData;
  resize(in, lowData, Size(sizeData, sizeData));

  SHOW_IMAGE(lowData, 0);
  // Histogram features
  Mat vhist = ProjectedHistogram(lowData, VERTICAL);
  Mat hhist = ProjectedHistogram(lowData, HORIZONTAL);

  // Last 10 is the number of moments components
  int numCols = vhist.cols + hhist.cols;

  Mat out = Mat::zeros(1, numCols, CV_32F);

  int j = 0;
  for (int i = 0; i < vhist.cols; i++) {
    out.at<float>(j) = vhist.at<float>(i);
    j++;
  }
  for (int i = 0; i < hhist.cols; i++) {
    out.at<float>(j) = hhist.at<float>(i);
    j++;
  }
  //std::cout << out << std::endl;

  return out;
}
Exemple #2
0
void init_vector_field() {
	int size = img_height*img_width;
	glTex_img = new unsigned char[size * 3];

	unsigned char* lic_img = new unsigned char[size];
	noise_img = new unsigned char[size];
	float *vx = new float[size];
	float *vy = new float[size];
	gen_noise_img(noise_img, img_width, img_height);
	test_gen_vector_field_ByElements(vx, vy, img_width, img_height); //generate vector field from a sparse set of feature elements

																	 //gen_lic(lic_img, noise_img, vx, vy, img_width, img_height);
	float *des_vx = 0, *dst_vy = 0;
	copyVF(vx, vy, des_vx, dst_vy, img_width, img_height);
	normalizeVF(des_vx, dst_vy, img_width, img_height);
	gen_lic(lic_img, noise_img, des_vx, dst_vy, img_width, img_height);


	gray2rgb(glTex_img, lic_img, img_width, img_height);
	//	test_draw_streamline_rgb(glTex_img, vx, vy, img_width, img_height);//draw streamlines on the vector field
	test_draw_arrow_rgb(glTex_img, vx, vy, img_width, img_height); //draw arrows on the vector field

#ifdef HAVE_OPENCV
#define SHOW_IMAGE(x) {cv::imshow(#x, x); cv::waitKey();}
	cv::Mat noiseImg(img_height, img_width, CV_8UC1, noise_img);
	cv::Mat licImg(img_height, img_width, CV_8UC1, lic_img);
	SHOW_IMAGE(licImg);
#endif

}
Exemple #3
0
void getGrayPlusLBP(const Mat& grayChar, Mat& features)
{
  // TODO: check channnels == 1
  SHOW_IMAGE(grayChar, 0);
  SHOW_IMAGE(255 - grayChar, 0);

  // resize to uniform size, like 20x32
  bool useResize = false;
  bool useConvert = true;
  bool useMean = true;
  bool useLBP = true;

  Mat char_mat;
  if (useResize) {
    char_mat.create(kGrayCharHeight, kGrayCharWidth, CV_8UC1);
    resize(grayChar, char_mat, char_mat.size(), 0, 0, INTER_LINEAR);
  }
  else {
    char_mat = grayChar;
  }
  SHOW_IMAGE(char_mat, 0);

  // convert to float
  Mat float_img;
  if (useConvert) {
    float scale = 1.f / 255;
    char_mat.convertTo(float_img, CV_32FC1, scale, 0);
  }
  else {
    float_img = char_mat;
  }
  SHOW_IMAGE(float_img, 0);

  // cut from mean, it can be optional

  Mat mean_img;
  if (useMean) {
    float_img -= mean(float_img);
    mean_img = float_img;
  }
  else {
    mean_img = float_img;
  }
  SHOW_IMAGE(mean_img, 0);

  // use lbp to get features, it can be changed to other
  Mat originImage = mean_img.clone();
  Mat lbpimage = libfacerec::olbp(mean_img);
  SHOW_IMAGE(lbpimage, 0);
  lbpimage = libfacerec::spatial_histogram(lbpimage, kCharLBPPatterns, kCharLBPGridX, kCharLBPGridY);

  // 32x20 + 16x16
  hconcat(mean_img.reshape(1, 1), lbpimage.reshape(1, 1), features);
}
Exemple #4
0
void getGrayPlusProject(const Mat& grayChar, Mat& features)
{
  // TODO: check channnels == 1
  SHOW_IMAGE(grayChar, 0);
  SHOW_IMAGE(255 - grayChar, 0);

  // resize to uniform size, like 20x32
  bool useResize = false;
  bool useConvert = true;
  bool useMean = true;
  bool useLBP = false;

  Mat char_mat;
  if (useResize) {
    char_mat.create(kGrayCharHeight, kGrayCharWidth, CV_8UC1);
    resize(grayChar, char_mat, char_mat.size(), 0, 0, INTER_LINEAR);
  }
  else {
    char_mat = grayChar;
  }
  SHOW_IMAGE(char_mat, 0);

  // convert to float
  Mat float_img;
  if (useConvert) {
    float scale = 1.f / 255;
    char_mat.convertTo(float_img, CV_32FC1, scale, 0);
  }
  else {
    float_img = char_mat;
  }
  SHOW_IMAGE(float_img, 0);

  // cut from mean, it can be optional

  Mat mean_img;
  if (useMean) {
    float_img -= mean(float_img);
    mean_img = float_img;
  }
  else {
    mean_img = float_img;
  }
  SHOW_IMAGE(mean_img, 0);

  // use lbp to get features, it can be changed to other
  Mat feautreImg;
  if (useLBP) {
    Mat lbpimage = libfacerec::olbp(char_mat);
    SHOW_IMAGE(lbpimage, 0);
    feautreImg = libfacerec::spatial_histogram(lbpimage, kCharLBPPatterns, kCharLBPGridX, kCharLBPGridY);
  }
  else {
    feautreImg = mean_img.reshape(1, 1);
  }
  SHOW_IMAGE(grayChar, 0);
  Mat binaryChar;
  threshold(grayChar, binaryChar, 0, 255, CV_THRESH_OTSU + CV_THRESH_BINARY);
  SHOW_IMAGE(binaryChar, 0);
  Mat projectFeature = charProjectFeatures(binaryChar, 32);

  hconcat(feautreImg.reshape(1, 1), projectFeature.reshape(1, 1), features);
}