Skip to content

Instantly share code, notes, and snippets.

@atinfinity
Last active February 3, 2018 02:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atinfinity/21b4970ec5f6977b250e5ec584dd90d5 to your computer and use it in GitHub Desktop.
Save atinfinity/21b4970ec5f6977b250e5ec584dd90d5 to your computer and use it in GitHub Desktop.
cv::selectROIsのサンプルコード
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <vector>
int main(int argc, char *argv[])
{
cv::Mat src = cv::imread("lena.jpg", cv::IMREAD_UNCHANGED);
if (src.empty())
{
std::cout << "Error: Could not load image file." << std::endl;
return -1;
}
std::vector<cv::Rect> rois;
// Enter or SpaceキーでROI指定
// ROI指定が終わったらEscキーを押下
cv::selectROIs("selectROIs", src, rois);
for (auto roi : rois)
{
cv::Mat roi_src = src(roi);
cv::imshow("Selected Region", roi_src);
cv::waitKey(0);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment