コード例 #1
0
ファイル: Video.cpp プロジェクト: chrischensy/OpenGazer
void VideoInput::updateFrame() {
	static HiResTimer timer;

	// Start the timer for fps calculations
	if(frameCount == 1)
		timer.start();

	static double trackerResolution = frame.size().height;
	frameCount++;

	// Every 20 frames, calculate the fps and reset timer
	if(frameCount % 20 == 0) {
		timer.stop();
		frameRate = (double) 20 / (timer.getElapsedTime()/1000.0);
		timer.start();
	}

	if (!(captureFromVideo && frameCount == 1)) {
		// If capturing from video and video size is not equal to desired resolution, carry on with resizing
		if (captureFromVideo && videoResolution != trackerResolution) {
			cv::Mat temp_image;
			_capture.read(temp_image);

			cv::Mat roi = temp_image;

			if (videoResolution == 720 && trackerResolution == 480) {
				roi = temp_image(cv::Rect(160, 0, 960, 720));
			} else if (videoResolution == 1080 && trackerResolution == 480) {
				roi = temp_image(cv::Rect(240, 0, 1440, 1080));
			}

			resize(roi, frame, frame.size(), 0, 0, CV_INTER_CUBIC);	
		} else {
			_capture.read(frame);
		}
	}
	
	if(frame.empty()) {
		throw Utils::QuitNow();
	}

	if (!captureFromVideo) {
		flip(frame, frame, 1);
	}
	
	copyToDebugFrame();
	cvtColor(frame, frameGrey, CV_BGR2GRAY);
}
コード例 #2
0
ファイル: create_engine.cpp プロジェクト: RolandHoGH/wesnoth
surface campaign::create_image_surface(const SDL_Rect& image_rect)
{
	surface temp_image(
		image::get_image(image::locator(image_label_)));

	return scale_surface(temp_image, image_rect.w, image_rect.h);
}
コード例 #3
0
ファイル: bitmap_image.cpp プロジェクト: sapphx/pl_FotoGK
void test16()
{
    std::string file_name("image.bmp");

    bitmap_image image(file_name);

    if (!image)
    {
        printf("test16() - Error - Failed to open '%s'\n",file_name.c_str());
        return;
    }

    double c1 = 0.9;
    double c2 = 0.5;
    double c3 = 0.3;
    double c4 = 0.7;

    bitmap_image plasma_image(image.width(),image.height());
    plasma(plasma_image,0,0,plasma_image.width(),plasma_image.height(),c1,c2,c3,c4,3.0,jet_colormap);

    bitmap_image temp_image(image);

    temp_image.alpha_blend(0.1, plasma_image);
    temp_image.save_image("test16_alpha_0.1.bmp");
    temp_image = image;

    temp_image.alpha_blend(0.2, plasma_image);
    temp_image.save_image("test16_alpha_0.2.bmp");
    temp_image = image;

    temp_image.alpha_blend(0.3, plasma_image);
    temp_image.save_image("test16_alpha_0.3.bmp");
    temp_image = image;

    temp_image.alpha_blend(0.4, plasma_image);
    temp_image.save_image("test16_alpha_0.4.bmp");
    temp_image = image;

    temp_image.alpha_blend(0.5, plasma_image);
    temp_image.save_image("test16_alpha_0.5.bmp");
    temp_image = image;

    temp_image.alpha_blend(0.6, plasma_image);
    temp_image.save_image("test16_alpha_0.6.bmp");
    temp_image = image;

    temp_image.alpha_blend(0.7, plasma_image);
    temp_image.save_image("test16_alpha_0.7.bmp");
    temp_image = image;

    temp_image.alpha_blend(0.8, plasma_image);
    temp_image.save_image("test16_alpha_0.8.bmp");
    temp_image = image;

    temp_image.alpha_blend(0.9, plasma_image);
    temp_image.save_image("test16_alpha_0.9.bmp");
}
コード例 #4
0
bool MonitorStream::sendFrame(const char *filepath, struct timeval *timestamp) {
  bool send_raw = ((scale>=ZM_SCALE_BASE)&&(zoom==ZM_SCALE_BASE));

  if ( type != STREAM_JPEG )
    send_raw = false;
  if ( !config.timestamp_on_capture && timestamp )
    send_raw = false;

  if ( !send_raw ) {
    Image temp_image(filepath);

    return sendFrame(&temp_image, timestamp);
  } else {
    int img_buffer_size = 0;
    static unsigned char img_buffer[ZM_MAX_IMAGE_SIZE];

    FILE *fdj = NULL;
    if ( (fdj = fopen(filepath, "r")) ) {
      img_buffer_size = fread(img_buffer, 1, sizeof(img_buffer), fdj);
      fclose(fdj);
    } else {
      Error("Can't open %s: %s", filepath, strerror(errno));
      return false;
    }

    // Calculate how long it takes to actually send the frame
    struct timeval frameStartTime;
    gettimeofday(&frameStartTime, NULL);
    
    fputs("--ZoneMinderFrame\r\nContent-Type: image/jpeg\r\n\r\n", stdout );
    fprintf(stdout, "Content-Length: %d\r\n", img_buffer_size);
    if ( fwrite(img_buffer, img_buffer_size, 1, stdout) != 1 ) {
      if ( ! zm_terminate )
        Warning("Unable to send stream frame: %s", strerror(errno));
      return false;
    }
    fputs("\r\n\r\n", stdout);
    fflush(stdout);

    struct timeval frameEndTime;
    gettimeofday(&frameEndTime, NULL);

    int frameSendTime = tvDiffMsec(frameStartTime, frameEndTime);
    if ( frameSendTime > 1000/maxfps ) {
      maxfps /= 2;
      Info("Frame send time %d msec too slow, throttling maxfps to %.2f", frameSendTime, maxfps);
    }

    last_frame_sent = TV_2_FLOAT(now);

    return true;
  }
  return false;
} // end bool MonitorStream::sendFrame(const char *filepath, struct timeval *timestamp)
コード例 #5
0
inline void test15()
{
   bitmap_image image("image.bmp");

   double c1 = 0.9;
   double c2 = 0.5;
   double c3 = 0.3;
   double c4 = 0.7;

   bitmap_image plasma_image(image.width(),image.height());
   plasma(plasma_image,0,0,plasma_image.width(),plasma_image.height(),c1,c2,c3,c4,3.0,jet_colormap);

   bitmap_image temp_image(image);

   temp_image.alpha_blend(0.1, plasma_image);
   temp_image.save_image("alpha_0.1.bmp");
   temp_image = image;

   temp_image.alpha_blend(0.2, plasma_image);
   temp_image.save_image("alpha_0.2.bmp");
   temp_image = image;

   temp_image.alpha_blend(0.3, plasma_image);
   temp_image.save_image("alpha_0.3.bmp");
   temp_image = image;

   temp_image.alpha_blend(0.4, plasma_image);
   temp_image.save_image("alpha_0.4.bmp");
   temp_image = image;

   temp_image.alpha_blend(0.5, plasma_image);
   temp_image.save_image("alpha_0.5.bmp");
   temp_image = image;

   temp_image.alpha_blend(0.6, plasma_image);
   temp_image.save_image("alpha_0.6.bmp");
   temp_image = image;

   temp_image.alpha_blend(0.7, plasma_image);
   temp_image.save_image("alpha_0.7.bmp");
   temp_image = image;

   temp_image.alpha_blend(0.8, plasma_image);
   temp_image.save_image("alpha_0.8.bmp");
   temp_image = image;

   temp_image.alpha_blend(0.9, plasma_image);
   temp_image.save_image("alpha_0.9.bmp");
}
コード例 #6
0
ファイル: Methods.cpp プロジェクト: Pranavgulati/VeriSmart
int Methods::preprocess(Mat *bin_image, vector<Image> *output,int doc) {
	Image temp_image(bin_image , 0, bin_image->rows, 0, bin_image->cols,Point2f(0,0));
	if (bin_image->channels()> 2){ cvtColor(*bin_image, *bin_image, CV_BGR2GRAY); }
	if (doc==1){
	adaptiveThreshold(*bin_image, *bin_image, 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY, 51, 45);}
	else{
		adaptiveThreshold(*bin_image, *bin_image, 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY, 13, 23);
	}
		int sensitivity = 4;
		CropImage(&temp_image, sensitivity);
		if (temp_image.x_right < 10 || temp_image.y_lower < 10){  return 0; }
		resize(*bin_image, *bin_image, Size(200, 100), 0, 0);
		//rotate here and then resize--1-11-2015
	//	signAlign(*bin_image);

		temp_image.y_lower = 100;
		temp_image.x_right = 200;
		temp_image.y_upper = 0;
		temp_image.x_left = 0;
		temp_image.imgCOG = calculateCOG(&temp_image);
		sampleCOG = temp_image.imgCOG;
		output->push_back(temp_image);
		return 1;
}
コード例 #7
0
std::vector<Vector3f> Retexture::applyGaussianFilter(std::vector<Vector3f> inpainted, int width, int height, int frosty)
{

      std::vector<Vector3f> temp_image (width * height);
      std::fill(temp_image.begin(), temp_image.end(), Vector3f(0, 0, 0));
      double total_weight;
      double val;

      if (!frosty) {
          // Not doin it
          return inpainted;
      }

      // Create the kernel

      double sigma = m_frosty;
      double s = sigma * 3;
      double kernel[(int) ((s * 2) + 1)];


      double coefficient = 1 / (sigma * sqrt(2 * M_PI));
      double exponent;
      double x;
      double gaussian;
      for (int i = 0; i < (2 * sigma * 3) + 1; ++i)
      {
        x = fabs(s - i);
        exponent = (-1 * x * x) / (2 * sigma * sigma);
        gaussian = coefficient * pow(M_E, exponent);
        kernel[i] = gaussian;
      }


      // Changing bounds so don't have to deal with edges now
      for (int i = 0; i < width; i++) {
        for (int j = 0;  j < height; j++) {

          val = 0;
          total_weight = 0;

          int index1D = width*j + i;

          for (int dx = -s; dx <= s; dx++) {
              if (dx+i >= 0 && dx+i < width) {
                  int origIndex = width * j + (i + dx);
                  temp_image[index1D] += (inpainted[origIndex] * kernel[(int) (dx+s)]);
                  total_weight += kernel[(int) (dx+s)];
              }
          }

          temp_image[index1D] = temp_image[index1D] / total_weight;
          //std::cout << temp_image[index1D] << std::endl;

        }
      }

      std::vector<Vector3f> temp_image2 (width * height);
      std::fill(temp_image2.begin(), temp_image2.end(), Vector3f(0, 0, 0));

      // Changing bounds so don't have to deal with edges now
      for (int i = 0; i < width; i++) {
        for (int j = 0;  j < height; j++) {

          val = 0;
          total_weight = 0;
          int index1D = width*j + i;

          for (int dy = -s;  dy <= s; dy++) {
              if (dy+j >= 0 && dy+j < height) {
                  int origIndex = width*(j+dy) + i;
                  temp_image2[index1D] += (temp_image[origIndex] * kernel[(int) (dy+s)]);
                  total_weight += kernel[(int) (dy+s)];
              }
          }

          temp_image2[index1D] = (temp_image2[index1D] / total_weight);//Vector3f(Vector3f(0.7, 0.4, 0.4).array() * (temp_image2[index1D] / total_weight).array());
        }
      }


    return temp_image2;
}
コード例 #8
0
DCStatus DataCleaner::scan_alimages(const char* path, int dir_id)
{ 
    DIR *root_dp;
    struct dirent *d_info;
    struct stat d_stat;   
    if ((root_dp = opendir(path)) == NULL)
    {
      cout<<"DataCleaner::scan_alimages: Open directory failed"<<endl;
      return DC_FAILED;
    }

    while((d_info = readdir(root_dp)) != 0)
    {
      if (!strcmp(d_info->d_name, ".") || (!strcmp(d_info->d_name, "..")))
        continue;
      
      string temp_path(path);
      temp_path += '/';
      temp_path += d_info->d_name;
  
      if (lstat(temp_path.c_str(), &d_stat) < 0)
      {
        cout<<"DataCleaner::scan_alimages: lstat file failed"<<endl;
        return DC_FAILED;
      }
      else
      {
        if(S_ISREG(d_stat.st_mode))
        {
            if (dir_id == -1)
            {
              cout<<"wrong root dir"<<endl;
              return DC_FAILED;
            } 
            string temp_image(d_info->d_name);
            this->images_[dir_id].push_back(temp_image);
        }
        else if (S_ISDIR(d_stat.st_mode))
        {
          string temp_image_dir(d_info->d_name);
          this->next_dir_id_++;
          this->image_dir_.push_back(make_pair(this->next_dir_id_,temp_image_dir));

          vector<string> new_dir;
          vector<ImgFeature*> new_feature_dir;
          vector<int> new_representative_dir;
          this->images_.push_back(new_dir);
          this->image_features_.push_back(new_feature_dir);
          this->image_representative_.push_back(new_representative_dir);

         if (scan_alimages(temp_path.c_str(),this->next_dir_id_) != DC_SUCCESS)
         {
           return DC_FAILED;
         }
        }
        else
        {
          cout<<"DataCleaner::scan_files: Wrong type file"<<endl;
        }
      }
    }
    closedir(root_dp);
    return DC_SUCCESS; 
}