forked from spmallick/learnopencv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request spmallick#281 from vishwesh5/master
Fix Hough Transform Code
- Loading branch information
Showing
11 changed files
with
189 additions
and
119 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
cmake_minimum_required(VERSION 2.8.12) | ||
|
||
PROJECT(HoughTransform) | ||
|
||
######################## EDIT IF REQUIRED #################### | ||
# ###Uncomment the line below and specify the path to OpenCV directory i.e. the path to the OpenCVConfig.cmake file. Check the examples given below. | ||
#SET(OpenCV_DIR Enter-the-path-of-OpenCV-installation-on-your-system) | ||
|
||
|
||
################### OpenCV_DIR Examples ##################### | ||
|
||
### MACOS : /usr/local/Cellar/opencv/3.3.1_1/share/OpenCV/ | ||
|
||
### UBUNTU : /usr/local/share/OpenCV/ | ||
|
||
### WINDOWS : C:\Users\yourname\Documents\opencv-3.3.1\build\install | ||
|
||
############################################################## | ||
|
||
|
||
|
||
|
||
################### ***DO NOT EDIT*** ##################### | ||
|
||
############# Common Instructions for all Users ############ | ||
find_package( OpenCV REQUIRED ) | ||
|
||
include_directories( ${OpenCV_INCLUDE_DIRS}) | ||
|
||
MACRO(add_example name) | ||
ADD_EXECUTABLE(${name} ${name}.cpp) | ||
TARGET_LINK_LIBRARIES(${name} ${OpenCV_LIBS} ) | ||
ENDMACRO() | ||
|
||
add_example(hough_circles) | ||
add_example(hough_lines) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#include <opencv2/core/core.hpp> | ||
#include <opencv2/highgui/highgui.hpp> | ||
#include <opencv2/opencv.hpp> | ||
#include <stdio.h> | ||
#include <iostream> | ||
|
||
using namespace cv; | ||
using namespace std; | ||
|
||
// variables to store images | ||
Mat dst, cimg, gray, img, edges; | ||
|
||
int initThresh; | ||
const int maxThresh = 1000; | ||
double th1,th2; | ||
|
||
// create a vector to store points of line | ||
vector<Vec4i> lines; | ||
|
||
void onTrackbarChange( int , void* ) | ||
{ | ||
cimg = img.clone(); | ||
dst = img.clone(); | ||
|
||
th1 = initThresh; | ||
th2 = th1 * 0.4; | ||
|
||
Canny(img,edges,th1,th2); | ||
|
||
// apply hough line transform | ||
HoughLinesP(edges, lines, 2, CV_PI/180, 50, 10, 100); | ||
|
||
// draw lines on the detected points | ||
for( size_t i = 0; i < lines.size(); i++ ) | ||
{ | ||
Vec4i l = lines[i]; | ||
line( dst, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(0,0,255), 1, LINE_AA); | ||
} | ||
|
||
// show the resultant image | ||
imshow("Result Image", dst); | ||
imshow("Edges", edges); | ||
} | ||
|
||
int main(int argc, char** argv) { | ||
const char* file = argv[1]; | ||
// Read image (color mode) | ||
img = imread(file, 1); | ||
dst = img.clone(); | ||
|
||
if(img.empty()) | ||
{ | ||
cout << "Error in reading image" << file<< endl; | ||
return -1; | ||
} | ||
|
||
// Convert to gray-scale | ||
cvtColor(img, gray, COLOR_BGR2GRAY); | ||
|
||
// Detect edges using Canny Edge Detector | ||
// Canny(gray, dst, 50, 200, 3); | ||
|
||
// Make a copy of original image | ||
// cimg = img.clone(); | ||
|
||
// Will hold the results of the detection | ||
namedWindow("Edges",1); | ||
namedWindow("Result Image", 1); | ||
|
||
// Declare thresh to vary the max_radius of circles to be detected in hough transform | ||
initThresh = 500; | ||
|
||
// Create trackbar to change threshold values | ||
createTrackbar("threshold", "Result Image", &initThresh, maxThresh, onTrackbarChange); | ||
onTrackbarChange(initThresh, 0); | ||
|
||
while(true) | ||
{ | ||
int key; | ||
key = waitKey( 1 ); | ||
if( (char)key == 27 ) | ||
{ break; } | ||
} | ||
|
||
destroyAllWindows(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.