35 lines
832 B
C++
35 lines
832 B
C++
|
|
#include "histo.h"
|
||
|
|
#include "opencv2/core/types.hpp"
|
||
|
|
#include <cassert>
|
||
|
|
#include <opencv2/core.hpp>
|
||
|
|
#include <opencv2/highgui.hpp>
|
||
|
|
#include <opencv2/imgproc.hpp>
|
||
|
|
#include <iostream>
|
||
|
|
|
||
|
|
using namespace cv;
|
||
|
|
|
||
|
|
int main(){
|
||
|
|
Mat img = imread("../kincseslada.png", IMREAD_COLOR);
|
||
|
|
Mat gray, mask;
|
||
|
|
cvtColor(img, gray, COLOR_BGR2GRAY);
|
||
|
|
threshold(gray, mask, 230, 255, THRESH_BINARY_INV);
|
||
|
|
medianBlur(mask, mask, 5);
|
||
|
|
|
||
|
|
|
||
|
|
std::vector<std::vector<Point>> contours;
|
||
|
|
findContours(mask, contours, RETR_EXTERNAL, CHAIN_APPROX_NONE);
|
||
|
|
|
||
|
|
assert(contours.size() == 2);
|
||
|
|
|
||
|
|
if(contours[0].size() > contours[1].size()){
|
||
|
|
drawContours(img, contours, 0, Scalar(0,0,255), 2);
|
||
|
|
}else{
|
||
|
|
drawContours(img, contours, 1, Scalar(0,0,255), 2);
|
||
|
|
}
|
||
|
|
|
||
|
|
imshow("img", img);
|
||
|
|
|
||
|
|
while(waitKey(3) != 'q');
|
||
|
|
return 0;
|
||
|
|
}
|