OpenCV обратная выпуклость - PullRequest
0 голосов
/ 14 марта 2019

Я использую этот код для поиска "дефектов выпуклости", но этот код находит "дефекты выпуклости" со стороны, я хочу сделать это со стороны, как на этой фотографии

enter image description here

enter image description here enter image description here

Пожалуйста, помогите мне, мне нужен ответ, я из Ирана, и я не могу найти какое-то тело, чтобы помочь мне. это мой код пожалуйста, не удаляйте мой вопрос. если вы хотите удалить, удалите ранее Вопрос.

#include "opencv2/imgcodecs.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/videoio.hpp"
#include <opencv2/highgui.hpp>
#include <opencv2/video.hpp>
#include <iostream>
#include <sstream>
#include <fstream>

using namespace cv;
using namespace std;


int main(int argc, char** argv)
{
    cv::Mat image = cv::imread("find_Contours.png");
    //Prepare the image for findContours
    cv::cvtColor(image, image, CV_BGR2GRAY);
    cv::threshold(image, image, 128, 255, CV_THRESH_BINARY);
    //Find the contours. Use the contourOutput Mat so the original image doesn't get overwritten
    std::vector<std::vector<cv::Point> > contours;
    cv::Mat contourOutput = image.clone();
    cv::findContours(contourOutput, contours, CV_RETR_LIST, CV_CHAIN_APPROX_NONE);
    ////convexityDefects 
    vector<vector<Point> >hull(contours.size());
    vector<vector<int> > hullsI(contours.size()); // Indices to contour points
    vector<vector<Vec4i>> defects(contours.size());
    for (int i = 0; i < contours.size(); i++)
    {
       convexHull(contours[i], hull[i], false);
    convexHull(contours[i], hullsI[i], true);;
        if (hullsI[i].size() > 3) // You need more than 3 indices          
        {
            convexityDefects(contours[i], hullsI[i], defects[i]);
        }
    }
    ///// Draw convexityDefects
    for (int i = 0; i < contours.size(); ++i)
    {
        for (const Vec4i& v : defects[i])
        {
            float depth = v[3]/256;
            if (depth >= 0) //  filter defects by depth, e.g more than 10
            {
                int startidx = v[0]; Point ptStart(contours[i][startidx]);
                int endidx = v[1]; Point ptEnd(contours[i][endidx]);
                int faridx = v[2]; Point ptFar(contours[i][faridx]);
                circle(image, ptFar, 4, Scalar(255, 255, 255), 2);
                cout << ptFar << endl;

            }
        }
    }
    //
    cv::imshow("Input Image", image);
    cvMoveWindow("Input Image", 0, 0);
    //
    waitKey(0);
}
...