Ask Your Question
0

How can I draw a boundary across a particular colour in opencv?

asked 2015-08-03 13:43:50 -0600

kaushikmit gravatar image
#include <iostream>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include<stdio.h>
#include<opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
    VideoCapture cap(0);
    while(true)
    {
    Mat img;
    cap.read(img);
    Mat dst;
    Mat imghsv;
    cvtColor(img, imghsv, COLOR_BGR2HSV);
    inRange(imghsv,
           Scalar(0, 30, 60),
           Scalar(20, 150, 255),
           dst
           );
    imshow("name",dst);
    if (waitKey(30) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
       {
            cout << "esc key is pressed by user" << endl;
            break;
       }
}

My inrange functions work fine. But I am unable to find a method with which i can draw a boundary to across all the pixels satisfying my threshold range

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-08-03 14:08:41 -0600

unxnut gravatar image

updated 2015-08-03 14:11:46 -0600

You should be able to use findcontour followed by drawcontour to achieve your objective. Here are the exact commands:

std::vector<std::vector<cv::Point>> contours;
std::vector<cv::Vec4i> hierarchy;
cv::findContours ( dst, contours, hierarchy, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE );
cv::drawContours ( dst, contours, -1, cv::Scalar(255), 1, CV_AA );
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-08-03 13:43:50 -0600

Seen: 227 times

Last updated: Aug 03 '15