initial commit
This commit is contained in:
parent
53e1f9e20e
commit
4b2bb43c62
7 changed files with 99 additions and 0 deletions
BIN
cat.png
Normal file
BIN
cat.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.3 KiB |
BIN
cat2.png
Normal file
BIN
cat2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6 KiB |
BIN
dog.png
Normal file
BIN
dog.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.5 KiB |
BIN
dog2.png
Normal file
BIN
dog2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.7 KiB |
42
find_lines.py
Executable file
42
find_lines.py
Executable file
|
@ -0,0 +1,42 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import numpy as np
|
||||
from math import pi
|
||||
import cv2
|
||||
import cv
|
||||
import sys
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
fn = sys.argv[1]
|
||||
print 'loading %s ...' % fn
|
||||
img1 = cv2.imread(fn, 0)
|
||||
img = cv.LoadImage(fn, cv.CV_LOAD_IMAGE_GRAYSCALE)
|
||||
size = cv.GetSize(img)
|
||||
|
||||
temp = cv.CreateImage(size, img.depth, img.nChannels)
|
||||
print temp
|
||||
cv.Smooth(img, temp)
|
||||
|
||||
canny = cv2.Canny(temp, 50, 100)
|
||||
color_dst = cv2.cvtColor(canny, cv2.COLOR_GRAY2BGR)
|
||||
lines = cv2.HoughLinesP(canny, 1, pi/90, 20, np.array([]), 5)
|
||||
|
||||
try:
|
||||
for line in lines[0]:
|
||||
cv2.line(color_dst, (line[0], line[1]), (line[2], line[3]), cv.RGB(255,0,0), 1, 8)
|
||||
except:
|
||||
pass
|
||||
|
||||
print lines[0].size
|
||||
|
||||
cv2.namedWindow("Original")
|
||||
cv2.imshow("Original", img)
|
||||
|
||||
cv2.namedWindow('Lines image')
|
||||
cv2.imshow('Lines image', color_dst)
|
||||
|
||||
cv2.waitKey()
|
||||
|
||||
|
||||
else:
|
||||
print "Please give a image path"
|
BIN
test.png
Normal file
BIN
test.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
57
test.py
Normal file
57
test.py
Normal file
|
@ -0,0 +1,57 @@
|
|||
#!/usr/bin/python
|
||||
# This is a standalone program. Pass an image name as a first parameter of the program.
|
||||
|
||||
import sys
|
||||
from math import sin, cos, sqrt, pi
|
||||
import cv
|
||||
import urllib2
|
||||
|
||||
# toggle between CV_HOUGH_STANDARD and CV_HOUGH_PROBILISTIC
|
||||
USE_STANDARD = True
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) > 1:
|
||||
filename = sys.argv[1]
|
||||
src = cv.LoadImage(filename, cv.CV_LOAD_IMAGE_GRAYSCALE)
|
||||
else:
|
||||
url = 'https://code.ros.org/svn/opencv/trunk/opencv/doc/pics/building.jpg'
|
||||
filedata = urllib2.urlopen(url).read()
|
||||
imagefiledata = cv.CreateMatHeader(1, len(filedata), cv.CV_8UC1)
|
||||
cv.SetData(imagefiledata, filedata, len(filedata))
|
||||
src = cv.DecodeImageM(imagefiledata, cv.CV_LOAD_IMAGE_GRAYSCALE)
|
||||
|
||||
|
||||
cv.NamedWindow("Source", 1)
|
||||
cv.NamedWindow("Hough", 1)
|
||||
|
||||
while True:
|
||||
dst = cv.CreateImage(cv.GetSize(src), 8, 1)
|
||||
color_dst = cv.CreateImage(cv.GetSize(src), 8, 3)
|
||||
storage = cv.CreateMemStorage(0)
|
||||
lines = 0
|
||||
cv.Canny(src, dst, 50, 200, 3)
|
||||
cv.CvtColor(dst, color_dst, cv.CV_GRAY2BGR)
|
||||
|
||||
if USE_STANDARD:
|
||||
lines = cv.HoughLines2(dst, storage, cv.CV_HOUGH_STANDARD, 1, pi / 180, 100, 0, 0)
|
||||
for (rho, theta) in lines[:100]:
|
||||
a = cos(theta)
|
||||
b = sin(theta)
|
||||
x0 = a * rho
|
||||
y0 = b * rho
|
||||
pt1 = (cv.Round(x0 + 1000*(-b)), cv.Round(y0 + 1000*(a)))
|
||||
pt2 = (cv.Round(x0 - 1000*(-b)), cv.Round(y0 - 1000*(a)))
|
||||
cv.Line(color_dst, pt1, pt2, cv.RGB(255, 0, 0), 3, 8)
|
||||
else:
|
||||
lines = cv.HoughLines2(dst, storage, cv.CV_HOUGH_PROBABILISTIC, 1, pi / 180, 50, 50, 10)
|
||||
for line in lines:
|
||||
cv.Line(color_dst, line[0], line[1], cv.CV_RGB(255, 0, 0), 3, 8)
|
||||
|
||||
cv.ShowImage("Source", src)
|
||||
cv.ShowImage("Hough", color_dst)
|
||||
|
||||
k = cv.WaitKey(0) % 0x100
|
||||
if k == ord(' '):
|
||||
USE_STANDARD = not USE_STANDARD
|
||||
if k == 27:
|
||||
break
|
Loading…
Add table
Add a link
Reference in a new issue