43 lines
1.2 KiB
C++
43 lines
1.2 KiB
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>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
using namespace cv;
|
|
|
|
int main(){
|
|
Mat img = imread("../some_objects.png", IMREAD_COLOR);
|
|
Mat gray, mask;
|
|
cvtColor(img, gray, COLOR_BGR2GRAY);
|
|
threshold(gray, mask, 230, 255, THRESH_BINARY);
|
|
|
|
std::vector<std::vector<Point>> contours;
|
|
findContours(mask, contours, RETR_EXTERNAL, CHAIN_APPROX_NONE);
|
|
|
|
for(int i = 0; i < contours.size(); i++){
|
|
Mat canvas = img.clone();
|
|
for(int j = 0; j < i; j++){
|
|
double d = matchShapes(contours[i], contours[j], CONTOURS_MATCH_I2, 0);
|
|
|
|
std::string s = to_string(d);
|
|
|
|
drawContours(canvas, contours, i, Scalar(0,0,255), 2);
|
|
drawContours(canvas, contours, j, Scalar(0,0,255), 2);
|
|
|
|
line(canvas, contours[i][0], contours[j][0], Scalar(100,100,100), 2);
|
|
|
|
putText(canvas, s, contours[j][0], FONT_HERSHEY_PLAIN, 1.5, Scalar(255, 255, 255));
|
|
}
|
|
}
|
|
|
|
imshow("img", img);
|
|
|
|
while(waitKey(3) != 'q');
|
|
return 0;
|
|
}
|