Created
January 11, 2017 06:53
-
-
Save tooshitaka/d7ab974c883c2bc4bf3dd6e76d10486a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Windows.h> | |
#include <iostream> | |
#include <opencv2/highgui.hpp> | |
#include <opencv2/imgproc.hpp> | |
#include <opencv2/video/background_segm.hpp> | |
#include <opencv2\video\tracking.hpp> | |
int main(int argc, char** argv) | |
{ | |
// Load input image | |
cv::Mat LoadedImage; | |
LoadedImage = cv::imread("lena.jpg", cv::IMREAD_COLOR); | |
std::cout << "Number of width:" << LoadedImage.rows << std::endl; | |
std::cout << "Number of height:" << LoadedImage.cols << std::endl; | |
// Show the input image | |
cv::namedWindow("InputImage", cv::WINDOW_AUTOSIZE); | |
cv::imshow("InputImage", LoadedImage); | |
cv::waitKey(1000); | |
// Parameters for the sliding window | |
int windows_n_rows = 40; | |
int windows_n_cols = 40; | |
// Step of each window | |
int StepSlide = 40; | |
// Copy Loaded image | |
cv::Mat DrawResultGrid = LoadedImage.clone(); | |
// Cycle row step | |
// Note the end condition: the rectange is drawn by left-top position | |
for (int row = 0; row <= LoadedImage.rows - windows_n_rows; row += StepSlide) | |
{ | |
// Cycle col step | |
for (int col = 0; col <= LoadedImage.cols - windows_n_cols; col += StepSlide) | |
{ | |
// 顔検出とか物体検出とかするときはここに処理を書く | |
// resulting window | |
cv::Rect windows(col, row, windows_n_rows, windows_n_cols); | |
cv::Mat DrawResultHere = LoadedImage.clone(); | |
// Draw only rectangle | |
cv::rectangle(DrawResultHere, windows, cv::Scalar(255), 1, 8, 0); | |
// Draw grid | |
cv::rectangle(DrawResultGrid, windows, cv::Scalar(255), 1, 8, 0); | |
// Selected windows roi | |
cv::Mat roi = LoadedImage(windows); | |
// Show rectangle | |
cv::namedWindow("Step 2 draw Rectangle", cv::WINDOW_AUTOSIZE); | |
cv::namedWindow("ROI", cv::WINDOW_AUTOSIZE); | |
cv::imshow("Step 2 draw Rectangle", DrawResultHere); | |
cv::imshow("ROI", roi); | |
cv::waitKey(100); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment