当前位置: 首页>>代码示例>>C++>>正文


C++ cv::imread方法代码示例

本文整理汇总了C++中cv::imread方法的典型用法代码示例。如果您正苦于以下问题:C++ cv::imread方法的具体用法?C++ cv::imread怎么用?C++ cv::imread使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cv的用法示例。


在下文中一共展示了cv::imread方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: center

TEST(hole_filling_test, elliptical_hole_on_repeated_texture_should_give_good_result)
{
    Mat img = imread("test_images/brick_pavement.jpg");
    convert_for_computation(img, 0.5f);

    // Add some hole
    Mat hole_mask = Mat::zeros(img.size(), CV_8U);

    Point center(100, 110);
    Size axis(20, 5);
    float angle = 20;
    ellipse(hole_mask, center, axis, angle, 0, 360, Scalar(255), -1);
    int patch_size = 7;
    HoleFilling hf(img, hole_mask, patch_size);

    // Dump image with hole as black region.
    Mat img_with_hole_bgr;
    cvtColor(img, img_with_hole_bgr, CV_Lab2BGR);
    img_with_hole_bgr.setTo(Scalar(0,0,0), hole_mask);
    imwrite("brick_pavement_hole.exr", img_with_hole_bgr);

    // Dump reconstructed image
    Mat filled = hf.run();
    cvtColor(filled, filled, CV_Lab2BGR);
    imwrite("brick_pavement_hole_filled.exr", filled);


    // The reconstructed image should be close to the original one, in this very simple case.
    Mat img_bgr;
    cvtColor(img, img_bgr, CV_Lab2BGR);
    double ssd = norm(img_bgr, filled, cv::NORM_L2SQR);
    EXPECT_LT(ssd, 0.2);
}
开发者ID:panmari,项目名称:patchMatch,代码行数:33,代码来源:HoleFillingTest.cpp

示例2: hf

TEST(hole_filling_test, rectangular_hole_on_repeated_texture_should_give_good_result)
{
    Mat img = imread("test_images/brick_pavement.jpg");
    convert_for_computation(img, 0.5f);

    // Add some hole
    Mat hole_mask = Mat::zeros(img.size(), CV_8U);

    hole_mask(Rect(72, 65, 5, 20)) = 255;
    int patch_size = 7;
    HoleFilling hf(img, hole_mask, patch_size);

    // Dump image with hole as black region.
    Mat img_with_hole_bgr;
    cvtColor(img, img_with_hole_bgr, CV_Lab2BGR);
    img_with_hole_bgr.setTo(Scalar(0,0,0), hole_mask);
    imwrite("brick_pavement_hole.exr", img_with_hole_bgr);

    // Dump reconstructed image
    Mat filled = hf.run();
    cvtColor(filled, filled, CV_Lab2BGR);
    imwrite("brick_pavement_hole_filled.exr", filled);


    // The reconstructed image should be close to the original one, in this very simple case.
    Mat img_bgr;
    cvtColor(img, img_bgr, CV_Lab2BGR);
    double ssd = norm(img_bgr, filled, cv::NORM_L2SQR);
    EXPECT_LT(ssd, 0.2);
}
开发者ID:panmari,项目名称:patchMatch,代码行数:30,代码来源:HoleFillingTest.cpp

示例3: appendImage

bool VideoStitcher::appendImage(string fileName) {
    Mat image = imread(fileName, CV_LOAD_IMAGE_COLOR);
    if (!openOut(image.size())) {
        return false;
    }

    _out.write(image);
    return true;
}
开发者ID:mkkelley,项目名称:videoproc,代码行数:9,代码来源:VideoStitcher.cpp

示例4: getImage

const Mat FileListImageSource::getImage() const
{
	if (index < 0 || index >= static_cast<int>(files.size()))
		return Mat();
	Mat image = imread(files[index].string(), CV_LOAD_IMAGE_COLOR);
	if (image.empty())
		throw runtime_error("image '" + files[index].string() + "' could not be loaded");
	return image;
}
开发者ID:smajida,项目名称:FeatureDetection,代码行数:9,代码来源:FileListImageSource.cpp

示例5: main

int main(){

	Mat img = imread("img.jpg");
	Size s = img.size();
	Mat gray;
	cvtColor(img, gray, CV_BGR2GRAY);

	Mat tmp = imread("mask.png");
	Mat mask;
	cvtColor(tmp,mask, CV_BGR2GRAY);
	
	Mat grad;
 	int scale = 1;
 	int delta = 0;
 	int ddepth = CV_16S;

	 /// Generate grad_x and grad_y
  	Mat grad_x, grad_y;
  	Mat abs_grad_x, abs_grad_y;

	Sobel( gray, grad_x, ddepth, 1, 0, 3, scale, delta, BORDER_DEFAULT );
  	convertScaleAbs( grad_x, abs_grad_x );	

	Sobel( gray, grad_y, ddepth, 0, 1, 3, scale, delta, BORDER_DEFAULT );
  	convertScaleAbs( grad_y, abs_grad_y );

  	/// Total Gradient (approximate)
  	addWeighted( abs_grad_x, 0.5, abs_grad_y, 0.5, 0, grad );

  	imwrite("grad.jpg",grad);


	Mat result = DTOCS(grad,mask);
	imwrite("DTOCS.png",result);


	Mat new_result = WDTOCS(grad,mask);
	imwrite("WDTOCS.png",new_result);

}
开发者ID:alessandroferrari,项目名称:GeodesicDistance,代码行数:40,代码来源:main.cpp

示例6: main


//.........这里部分代码省略.........
        vector<float> coords = getNextLineAndSplitIntoFloats(region_file);

        if (coords.size() == 4) {
            rect = Rect(coords[0], coords[1], coords[2], coords[3]);
        }

        else if (coords.size() == 8)
        {
            //Split into x and y coordinates
            vector<float> xcoords;
            vector<float> ycoords;

            for (size_t i = 0; i < coords.size(); i++)
            {
                if (i % 2 == 0) xcoords.push_back(coords[i]);
                else ycoords.push_back(coords[i]);
            }

            float xmin = *min_element(xcoords.begin(), xcoords.end());
            float xmax = *max_element(xcoords.begin(), xcoords.end());
            float ymin = *min_element(ycoords.begin(), ycoords.end());
            float ymax = *max_element(ycoords.begin(), ycoords.end());

            rect = Rect(xmin, ymin, xmax-xmin, ymax-ymin);
            cout << "Found bounding box" << xmin << " " << ymin << " " <<  xmax-xmin << " " << ymax-ymin << endl;
        }

        else {
            cerr << "Invalid Bounding box format" << endl;
            return 0;
        }

        //Read first image
        Mat im0 = imread(files[0]);
        Mat im0_gray;
        cvtColor(im0, im0_gray, CV_BGR2GRAY);

        //Initialize cmt
        cmt.initialize(im0_gray, rect);

        //Write init region to output file
        ofstream output_file("output.txt");
        output_file << rect.x << ',' << rect.y << ',' << rect.width << ',' << rect.height << std::endl;

        //Process images, write output to file
        for (size_t i = 1; i < files.size(); i++)
        {
            FILE_LOG(logINFO) << "Processing frame " << i << "/" << files.size();
            Mat im = imread(files[i]);
            Mat im_gray;
            cvtColor(im, im_gray, CV_BGR2GRAY);
            cmt.processFrame(im_gray);
            if (verbose_flag)
            {
                display(im, cmt);
            }
            rect = cmt.bb_rot.boundingRect();
            output_file << rect.x << ',' << rect.y << ',' << rect.width << ',' << rect.height << std::endl;
        }

        output_file.close();

        return 0;
    }

    //Normal mode
开发者ID:tesYolan,项目名称:CppMT,代码行数:67,代码来源:main.cpp

示例7: main


//.........这里部分代码省略.........
		vector<string>::iterator start_image;
		if (argc == 4) {
			// Set first image as start point of the loop over the folder of images
			start_image = folderFiles.begin();
		} else {
			// Set received argument as start point of the loop over the folder of images
			start_image = std::find(folderFiles.begin(), folderFiles.end(),
					argv[4]);
		}

		for (vector<string>::iterator image = start_image;
				image != folderFiles.end(); ++image) {
			if ((*image).find(".jpg") != string::npos) {
				printf("%s\n", (*image).c_str());
				Features features = detectAndDescribeFeatures(
						argv[2] + string("/") + (*image));

				string descriptorFileName(argv[3]);
				descriptorFileName += "/"
						+ (*image).substr(0, (*image).size() - 4) + ".key";
				writeFeaturesToFile(descriptorFileName, features);
			}
		}
	} else if (string(argv[1]).compare("-featsel") == 0) {
		string keypointsFolderPath(argv[2]);
		string masksFolderPath(argv[3]);
		string outputFolderPath(argv[4]);

		vector<string> maskFiles;

		Features features, selectedFeatures;

		for (string filename : folderFiles) {
			if (filename.find(".key") != string::npos) {
				string keypointFilepath = keypointsFolderPath + "/" + filename;
				readKeypoints(keypointFilepath.c_str(), features.keypoints,
						features.descriptors);

				StringUtils::split(filename.c_str(), '/').back();
				filename.resize(filename.size() - 4);

				string maskPath = masksFolderPath + "/" + filename
						+ MASK_FILE_EXTENSION;

				vector<Point2f> polygon = readMask(maskPath.c_str());

				printf("Selecting features\n");
				int count = 0;
				selectedFeatures.keypoints.clear();
				for (KeyPoint p : features.keypoints) {
					int inCont = pointPolygonTest(polygon, p.pt, false);
					if (inCont != -1) {
						selectedFeatures.keypoints.push_back(p);
						selectedFeatures.descriptors.push_back(
								features.descriptors.row(count));
					}
					count++;
				}
				printf("  Selected [%d] features\n",
						(int) selectedFeatures.keypoints.size());

				string outputFeaturesPath = outputFolderPath + "/" + filename
						+ KEYPOINT_FILE_EXTENSION;

				writeFeaturesToFile(outputFeaturesPath, selectedFeatures);
			}
		}
	} else if (string(argv[1]).compare("-visualkp") == 0) {

		string keypointsFolderPath(argv[2]);
		string imagesFolderPath(argv[3]);
		string outputImagesFolderPath(argv[4]);

		Features features;
		for (string filename : folderFiles) {
			if (filename.find(".key") != string::npos) {

				string keypointFilepath = keypointsFolderPath + "/" + filename;
				readKeypoints(keypointFilepath.c_str(), features.keypoints,
						features.descriptors);

				string imgPath = imagesFolderPath + "/"
						+ StringUtils::parseImgFilename(filename);

				printf("Reading image [%s]\n", imgPath.c_str());
				Mat img = imread(imgPath, CV_LOAD_IMAGE_COLOR);

				drawKeypoints(img, features.keypoints, img, cvScalar(255, 0, 0),
						DrawMatchesFlags::DEFAULT);
				string imgWithKeysPath = outputImagesFolderPath + "/"
						+ StringUtils::parseImgFilename(filename, "_with_keys");
				printf("Writing image [%s]\n", imgWithKeysPath.c_str());
				cv::imwrite(imgWithKeysPath, img);

			}
		}
	}

	return EXIT_SUCCESS;
}
开发者ID:catree,项目名称:LocRecBgFeat,代码行数:101,代码来源:FeatureExtractSelect.cpp

示例8: getImage

const Mat FileListImageSource::getImage() const
{
	if (index < 0 || index >= files.size())
		return Mat();
	return imread(files[index].string(), 1);
}
开发者ID:lysvincent,项目名称:FeatureDetection,代码行数:6,代码来源:FileListImageSource.cpp

示例9: train

Params ImageRetriever::train( const string& dirname, const Params& preconf )
{
	path dir = dirname;
	RuntimeCheck(is_directory(dir), "Error: failed to load image directory.");

	vector<string> names;
	// load image names
	for (auto it = directory_iterator(dir); it != directory_iterator(); ++it)
		names.push_back((it->path()).string());

	// shuffle the images
	std::random_shuffle(names.begin(), names.end());

	const bool with_vocabulary = not preconf.vocabulary.empty();
	const float hessian = preconf.hessian;
	const int voclen = preconf.voclen;
	const int binlen = preconf.binarylen;
	const int imgmaxlen = preconf.imgmaxlen;

	// load images and extract local feature for training.
	auto lfextractor = m_bwextractor.lfextractor();
	const int maxnum = 1000 * voclen;
	const int dims = lfextractor.size();
	Mat descs(maxnum, dims, DataType<float>::type); //TODO add auto configuration for feature type.
	int count = 0;
	for (auto it = names.begin(); it != names.end(); ++it) {
		std::cout << "\t" << *it << std::endl;
		Mat image = imread(*it);
		image = reformed(image, imgmaxlen);

		auto lfs = lfextractor.compute(image);
		Mat desc = std::get<1>(lfs);
		int num = desc.rows;

		desc.copyTo(descs.rowRange(count, count+num));
		count += num;

		if (count > maxnum)
			break;
	}

	// copy the valid descriptors for training.
	if (maxnum > count)
		descs = descs.rowRange(0, count);

	Params param = preconf;

	// train the parameters and store in Param struct.
	if (with_vocabulary) {
		auto ret = m_bwextractor.train(descs, preconf.vocabulary, binlen);
		param.projection = std::get<0>(ret);
		param.thresholds = std::get<1>(ret);
	}
	else {
		auto ret = m_bwextractor.train(descs, voclen, binlen);
		param.vocabulary = std::get<0>(ret);
		param.projection = std::get<1>(ret);
		param.thresholds = std::get<2>(ret);
	}

	return param;
}
开发者ID:PierreHao,项目名称:Cires,代码行数:62,代码来源:image_retriever.cpp


注:本文中的cv::imread方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。