Exemplo n.º 1
0
int main (int argc, char *argv[]) {
    if(argc != 2) {
        cout << "[error]:inputed unread image path.";
        return -1;
    }
    Mosaic *mosaic = new Mosaic(argv[1]);
    //mosaic->display_grayscale_image(1000);
    //mosaic->display_edge_image(10000);
    mosaic->detect_block();
    return 0;
}
Exemplo n.º 2
0
int main(int argc, char *argv[]) {
    if (argc != 2) {
        cout << "Stitch putanja_do_direktorija" << endl;
        return -1;
    }

    //String path = "/home/stanko/ClionProjects/Stitch/data/";
    String path = argv[1];
    //vector<Geo> gpsLocations;
    std::vector<UMat> imgs = loadImages(path);
    //std::vector<cuda::GpuMat> imgs = convertToGpu(imgs_);

    Mat matching_mask = Mat::zeros(imgs.size(), imgs.size(), CV_8U);

    for (int i = 0; i < imgs.size() - 1; ++i) {
        matching_mask.at<char>(i, i+1) = 1;
        matching_mask.at<char>(i+1, i) = 1;
    }

    UMat matching_mask_;
    matching_mask.copyTo(matching_mask_);

    // Stitcher se inicijalizira s defaultnim parametrima
    // rucno namjestamo SIFT feature
    Mosaic stitcher = Mosaic::createDefault(false);
    stitcher.setFeaturesFinder(makePtr<MosaicUAV::detail::SiftFeaturesFinder>());
    //stitcher.setMatchingMask(matching_mask_);
    stitcher.setCompositingResol(0.6);

    int64 t = getTickCount();
    cout << "Pocinje racunanje" << endl;

    Mat pano;
    Mosaic::Status status = stitcher.stitch(imgs, pano);

    cout << "Trebalo je " << (getTickCount() - t) / getTickFrequency() << " s" << endl;

    if (status != Mosaic::OK) {
        cout << "Can't stitch images, error code = " << status << endl;
        return -1;
    }

    imwrite("result.jpg", pano);

    return 0;
}
Exemplo n.º 3
0
int main(int argc, char *argv[]) {
  opterr = 0;

  int width = -1;
  int height = -1;
  int max_frames = -1;
  const char *in = NULL;
  const char *out = NULL;
  bool time = false;
  int stripType = Blend::STRIP_TYPE_THIN;

  const struct option long_options[] = {
    {"width",  required_argument, 0, 'w'},
    {"height", required_argument, 0, 'h'},
    {"in",     required_argument, 0, 'i'},
    {"out",    required_argument, 0, 'o'},
    {"strip",  required_argument, 0, 's'},
    {"max",    required_argument, 0, 'm'},
    {"time",   no_argument      , 0, 't'},
    {0,        0,                 0, 0}
  };

  int c;

  if (argc == 1) {
    usage();
    return 0;
  }

  while (1) {
    c = getopt_long(argc, argv, "w:h:i:o:s:m:t", long_options, NULL);
    if (c == -1) {
      break;
    }

    switch (c) {
    case 'w':
      width = atoi(optarg);
      break;

    case 'h':
      height = atoi(optarg);
      break;

    case 'i':
      in = optarg;
      break;

    case 'o':
      out = optarg;
      break;

    case 't':
      time = true;
      break;

    case 's':
      stripType = atoi(optarg);
      break;

    case 'm':
      max_frames = atoi(optarg);
      break;

    case '?':
      usage();
      return 0;
    }
  }

  // validate
  if (width <= 0) {
    std::cerr << "invalid width " << width << std::endl;
    return 1;
  }

  if (height <= 0) {
    std::cerr << "invalid height " << height << std::endl;
    return 1;
  }

  if (!in) {
    std::cerr << "input file not provided" << std::endl;
    return 1;
  }

  if (!out) {
    std::cerr << "output file not provided" << std::endl;
    return 1;
  }

  if (stripType < 0 || stripType > 1) {
    std::cerr << "invalid strip type " << stripType << std::endl;
    return 1;
  }

  // input
  int fd = open(in, O_RDONLY);
  if (fd == -1) {
    perror("open");
    return 1;
  }


  int size = (width * height * 12) / 8;

  std::cout << "input width = " << width << ", height = " << height << std::endl;
  std::cout << "strip type: " << stripType << " (" << strips[stripType] << ")" << std::endl;

  int frames = count_frames(fd, size);

  if (frames == -1) {
    close(fd);
    return 1;
  }

  if (max_frames > 0) {
    frames = MIN(frames, max_frames);
  }

  // initialize our mosaicer
  Mosaic m;
  if (!m.initialize(blendingType, stripType, width, height, frames, true, 5.0f)) {
    std::cerr << "Failed to initialize mosaicer" << std::endl;
    close(fd);
    return 1;
  }

  std::vector<int> times;
  std::vector<unsigned char *> mosaic_frames;
  unsigned char *in_data = NULL;

  for (int x = 0; x < frames; x++) {
    // allocate:
    if (!in_data) {
      in_data = new unsigned char[size];
    }

    if (read(fd, in_data, size) == size) {
      // process
      int time = timeNow();
      int ret = m.addFrame(in_data);
      time = timeNow() - time;

      times.push_back(time);

      if (ret == Mosaic::MOSAIC_RET_OK || ret == Mosaic::MOSAIC_RET_FEW_INLIERS) {
	mosaic_frames.push_back(in_data);
	in_data = NULL;
      }
    } else {
      break;
    }
  }

  if (in_data) {
    delete[] in_data;
  }

  close(fd);

  std::cout << "Used " << mosaic_frames.size() << " frames" << std::endl;

  // output
  // TODO: what are those?
  float progress = 0;
  bool cancel = false;

  int64_t stitchingTime = timeNow();

  if (m.createMosaic(progress, cancel) != Mosaic::MOSAIC_RET_OK) {
    std::cerr << "Failed to stitch" << std::endl;
    return 1;
  }

  stitchingTime = timeNow() - stitchingTime;

  ImageType yuv = m.getMosaic(width, height);
  ImageType rgb = ImageUtils::allocateImage(width, height, 3);
  ImageUtils::yvu2rgb(rgb, yuv, width, height);

  for (int x = 0; x < mosaic_frames.size(); x++) {
    delete[] mosaic_frames[x];
  }

  mosaic_frames.clear();

  bool res = write_png(out, rgb, width, height);
  ImageUtils::freeImage(rgb);
  if (!res) {
    return 1;
  }

  std::cout << "Wrote mosaic image to " << out << std::endl;
  std::cout << "Width = " << width << " height = " << height << std::endl;

  if (time) {
    std::cout << "Average frame time = " << std::accumulate(times.begin(), times.end(), 0) / times.size() << "ms" << std::endl;
    std::cout << "Final stitching time = " << stitchingTime << "ms" << std::endl;
  }

  return 0;
}
Exemplo n.º 4
0
int main(int argc, char **argv)
{
    struct timespec t1, t2, t3;

    int width, height;
    float totalElapsedTime = 0;

    const char *basename;
    const char *filename;

    if (argc != 3) {
        printf("Usage: %s input_dir output_filename\n", argv[0]);
        return 0;
    } else {
        basename = argv[1];
        filename = argv[2];
    }

    // Load the images outside the computational kernel
    int totalFrames = loadImages(basename, width, height);

    if (totalFrames == 0) {
        printf("Image files not found. Make sure %s exists.\n",
               basename);
        return 1;
    }

    printf("%d frames loaded\n", totalFrames);


    // Interesting stuff is here
    for (int iteration = 0; iteration < KERNEL_ITERATIONS; iteration++)  {
        Mosaic mosaic;

        mosaic.initialize(blendingType, stripType, width, height, -1, false, 0);

        clock_gettime(CLOCK_MONOTONIC, &t1);
        for (int i = 0; i < totalFrames; i++) {
            mosaic.addFrame(yvuFrames[i]);
        }
        clock_gettime(CLOCK_MONOTONIC, &t2);

        float progress = 0.0;
        bool cancelComputation = false;

        mosaic.createMosaic(progress, cancelComputation);

        int mosaicWidth, mosaicHeight;
        ImageType resultYVU = mosaic.getMosaic(mosaicWidth, mosaicHeight);

        ImageType imageRGB = ImageUtils::allocateImage(
            mosaicWidth, mosaicHeight, ImageUtils::IMAGE_TYPE_NUM_CHANNELS);

        clock_gettime(CLOCK_MONOTONIC, &t3);

        float elapsedTime =
            (t3.tv_sec - t1.tv_sec) + (t3.tv_nsec - t1.tv_nsec)/1e9;
        float addImageTime =
            (t2.tv_sec - t1.tv_sec) + (t2.tv_nsec - t1.tv_nsec)/1e9;
        float stitchImageTime =
            (t3.tv_sec - t2.tv_sec) + (t3.tv_nsec - t2.tv_nsec)/1e9;

        totalElapsedTime += elapsedTime;

        printf("Iteration %d: %dx%d moasic created: "
               "%.2f seconds (%.2f + %.2f)\n",
               iteration, mosaicWidth, mosaicHeight,
               elapsedTime, addImageTime, stitchImageTime);

        // Write the output only once for correctness check
        if (iteration == 0) {
            ImageUtils::yvu2rgb(imageRGB, resultYVU, mosaicWidth,
                                mosaicHeight);
            ImageUtils::writeBinaryPPM(imageRGB, filename, mosaicWidth,
                                       mosaicHeight);
        }
    }
    printf("Total elapsed time: %.2f seconds\n", totalElapsedTime);

    return 0;
}
Exemplo n.º 5
0
int main()
{
	// Setup directory and folder paths, no recursive solution yet
	string image_name = "zlatan_blue-yellow_background_1440x900.jpg";

	// ----> Directory for: KRISTOFER <-----
	//string mainDirectory = "C:/Users/StoffesBok/Bilddatabaser_TNM025/dataset/";
	//cv::Mat image_temp = imread("C:/Users/StoffesBok/Bilddatabaser_TNM025/dataset/zlatan/zlatan_blue_background_1920x1080.jpg", 1);

	// ----> Directory for: GABRIEL <-----
	string mainDirectory = "C:/Users/Gabriel/Desktop/Bildatabaser/Bilddatabaser_TNM025/dataset/";
	Mat image_temp = imread("C:/Users/Gabriel/Desktop/Bildatabaser/Bilddatabaser_TNM025/dataset/zlatan/" + image_name, 1);

	if (!image_temp.data){
		cout << "Zlatan is too big!" << endl; return -1;}
	
	string extension = "2"; // 2 => 32x32, 3 => 16x16, 4 => 8x8
	int patch_size = 32;

	vector<string> inputFolders = { "andy_warhol", "animal", "beach", "cat", "claude_monet", "colorful",
								    "doll", "elegant", "flower", "food", "formal", "garden" };
	
	vector<string> animalFolder = { "animal4", "garden4", "beach"};

	for (int i = 0; i < inputFolders.size(); i++)
		inputFolders[i] += extension;

	// Initilize the database
	DB database = DB();
	database.loadImages(mainDirectory, inputFolders);
	
	// Choose mode: 
	// 0 if you want to see zlatan
	// 1 if you want to start the cam
#define CAM 1

	if (CAM)
	{
		VideoCapture cap(0);
		char *name = "Rendering";
		char *original = "Original";
		namedWindow(name, CV_WINDOW_FULLSCREEN);
		namedWindow(original, CV_WINDOW_FULLSCREEN);

		if (!cap.isOpened())
		{
			cout << "Could not open the camera! " << endl;
			return -1;
		}

		int count = 0;
		vector<double> times;
		while (true)
		{	
			double t = (double)getTickCount();
			Mat frame;
			
			// Grab a frame from camera
			cap >> frame;
			resize(frame, frame, Size(300, 300), 0, 0, INTER_AREA);
			imshow(original, frame);

			double a = (double)getTickCount();
			// Create a database of patches from a query image
			Mosaic zlatan = Mosaic(frame, patch_size);
			a = ((double)getTickCount() - a) / getTickFrequency();

			// Match similar images in the mosaic with the database with PCA/KLT and L2-norm
			zlatan.matchSimiliarImage(database);
			

			// Reconstruct the matched images
			zlatan.reconstructImageFromDB();

			double b = (double)getTickCount();
			t = (b - t) / getTickFrequency();
			count++;
			if (count % 1 == 0)
			{
				cout << "TOTAL TIME: " << t << endl;
				cout << "TIME FOR CONSTRUCTOR: " << a << endl;

				cout << "FPS: " << (double) (1.0 / t)<< endl;
				count = 0;
			}

			//resize(zlatan.image_result_, zlatan.image_result_, Size(200, 200), 0, 0, INTER_AREA);
			imshow(name, zlatan.image_result_);
			
			cvWaitKey(1);
		}
	}
	else
	{
Exemplo n.º 6
0
Mosaic Mosaic::createDefault(bool try_use_gpu) {
    Mosaic stitcher;
    stitcher.setRegistrationResol(0.6);
    stitcher.setSeamEstimationResol(0.1);
    stitcher.setCompositingResol(ORIG_RESOL);
    stitcher.setPanoConfidenceThresh(1);
    stitcher.setWaveCorrection(true);
    stitcher.setWaveCorrectKind(detail::WAVE_CORRECT_HORIZ);
    stitcher.setFeaturesMatcher(makePtr<detail::BestOf2NearestMatcher>(try_use_gpu));
    stitcher.setBundleAdjuster(makePtr<detail::BundleAdjusterRay>());

#ifdef HAVE_OPENCV_CUDALEGACY
    if (try_use_gpu && cuda::getCudaEnabledDeviceCount() > 0) {
#ifdef HAVE_OPENCV_XFEATURES2D
        stitcher.setFeaturesFinder(makePtr<detail::SurfFeaturesFinderGpu>());
#else
        stitcher.setFeaturesFinder(makePtr<detail::OrbFeaturesFinder>());
#endif
        stitcher.setWarper(makePtr<TranslationPlaneWarperGpu>());
        //stitcher.setWarper(makePtr<TranslationPlaneWarper>());
        stitcher.setSeamFinder(makePtr<detail::GraphCutSeamFinderGpu>());
    } else
#endif
    {
#ifdef HAVE_OPENCV_XFEATURES2D
        stitcher.setFeaturesFinder(makePtr<detail::SurfFeaturesFinder>());
#else
        stitcher.setFeaturesFinder(makePtr<detail::OrbFeaturesFinder>());
#endif
        stitcher.setWarper(makePtr<TranslationPlaneWarper>());
        stitcher.setSeamFinder(makePtr<detail::GraphCutSeamFinder>(detail::GraphCutSeamFinderBase::COST_COLOR));
    }

    stitcher.setExposureCompensator(makePtr<detail::BlocksGainCompensator>());
    stitcher.setBlender(makePtr<detail::MultiBandBlender>(try_use_gpu, false));

    stitcher.work_scale_ = 1;
    stitcher.seam_scale_ = 1;
    stitcher.seam_work_aspect_ = 1;
    stitcher.warped_image_scale_ = 1;

    return stitcher;
}