Skip to content

Instantly share code, notes, and snippets.

@vernwalrahul
Created January 9, 2017 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vernwalrahul/5d775f30197e8ae4438f58ba5d044dcf to your computer and use it in GitHub Desktop.
Save vernwalrahul/5d775f30197e8ae4438f58ba5d044dcf to your computer and use it in GitHub Desktop.
// Buoy_task.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<opencv2/opencv.hpp>
#include<stdio.h>
#include<iostream>
using namespace std;
using namespace cv;
Mat frame;
Mat frame1(480, 640, CV_8UC3);
Mat gray(480, 640, CV_8UC1);
//Mat contour(480, 640, CV_8UC1);
vector<Vec3f> circles;
int lth = 50, uth = 100;
void disp(int p, void *k)
{
Canny(frame, gray, lth, uth);
imshow("gray: ", gray);
waitKey(0);
}
int main()
{
VideoCapture vc("G:\\Buoy task\\task_buoy_2_20_seconds.avi");
vc >> frame;
//namedWindow("Change:", WINDOW_AUTOSIZE);
//createTrackbar("Lower th:", "Change:", &lth, 255, disp, NULL);
//createTrackbar("Upper th:", "Change:", &uth, 255, disp, NULL);
while (frame.data)
{
//imshow("original: ", frame);
cvtColor(frame, frame1, CV_BGR2HSV);
for (int k = 0; k <= 7;k++)
GaussianBlur(frame1, frame1, Size(3, 3), 0, 0);
//imshow("hsv: ", frame1);
//inRange(frame, Scalar(90, 0, 0), Scalar(100, 255, 255), gray);
Canny(frame1, gray, 10, 100, 3);
//cvtColor(frame1, gray, CV_BGR2GRAY);
//imshow("gray:", gray);
GaussianBlur(gray, gray, Size(3, 3),0,0);
HoughCircles(gray, circles, CV_HOUGH_GRADIENT, 1, gray.rows / 3, 100, 30, 20, 70);
for (size_t i = 0; i < circles.size(); i++)
{
Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
int radius = cvRound(circles[i][2]);
//cout << "Radius=" << radius << endl;
// circle center
circle(frame, center, 3, Scalar(0, 255, 0), -1, 8, 0);
// circle outline
circle(frame, center, radius, Scalar(0, 0, 255), 3, 8, 0);
}
imshow("detected: ", frame);
waitKey(50);
vc >> frame;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment