Commit b76d3514 authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

Merge pull request #5128 from ageitgey:ag-prevent-demos-from-autorunning

parents 4a2aad5b e976c448
......@@ -95,32 +95,34 @@ def onmouse(event,x,y,flags,param):
cv2.circle(img,(x,y),thickness,value['color'],-1)
cv2.circle(mask,(x,y),thickness,value['val'],-1)
# print documentation
print __doc__
if __name__ == '__main__':
# Loading images
if len(sys.argv) == 2:
# print documentation
print __doc__
# Loading images
if len(sys.argv) == 2:
filename = sys.argv[1] # for drawing purposes
else:
else:
print "No input image given, so loading default image, ../data/lena.jpg \n"
print "Correct Usage: python grabcut.py <filename> \n"
filename = '../data/lena.jpg'
img = cv2.imread(filename)
img2 = img.copy() # a copy of original image
mask = np.zeros(img.shape[:2],dtype = np.uint8) # mask initialized to PR_BG
output = np.zeros(img.shape,np.uint8) # output image to be shown
img = cv2.imread(filename)
img2 = img.copy() # a copy of original image
mask = np.zeros(img.shape[:2],dtype = np.uint8) # mask initialized to PR_BG
output = np.zeros(img.shape,np.uint8) # output image to be shown
# input and output windows
cv2.namedWindow('output')
cv2.namedWindow('input')
cv2.setMouseCallback('input',onmouse)
cv2.moveWindow('input',img.shape[1]+10,90)
# input and output windows
cv2.namedWindow('output')
cv2.namedWindow('input')
cv2.setMouseCallback('input',onmouse)
cv2.moveWindow('input',img.shape[1]+10,90)
print " Instructions: \n"
print " Draw a rectangle around the object using right mouse button \n"
print " Instructions: \n"
print " Draw a rectangle around the object using right mouse button \n"
while(1):
while(1):
cv2.imshow('output',output)
cv2.imshow('input',img)
......@@ -171,4 +173,4 @@ while(1):
mask2 = np.where((mask==1) + (mask==3),255,0).astype('uint8')
output = cv2.bitwise_and(img2,img2,mask=mask2)
cv2.destroyAllWindows()
cv2.destroyAllWindows()
......@@ -10,24 +10,25 @@ import cv2
import numpy as np
import sys
if __name__ == '__main__':
print __doc__
try:
print __doc__
try:
fn = sys.argv[1]
except:
except:
fn = "../data/board.jpg"
src = cv2.imread(fn, 1)
img = cv2.cvtColor(src, cv2.COLOR_BGR2GRAY)
img = cv2.medianBlur(img, 5)
cimg = src.copy() # numpy function
src = cv2.imread(fn, 1)
img = cv2.cvtColor(src, cv2.COLOR_BGR2GRAY)
img = cv2.medianBlur(img, 5)
cimg = src.copy() # numpy function
circles = cv2.HoughCircles(img, cv2.HOUGH_GRADIENT, 1, 10, np.array([]), 100, 30, 1, 30)
a, b, c = circles.shape
for i in range(b):
circles = cv2.HoughCircles(img, cv2.HOUGH_GRADIENT, 1, 10, np.array([]), 100, 30, 1, 30)
a, b, c = circles.shape
for i in range(b):
cv2.circle(cimg, (circles[0][i][0], circles[0][i][1]), circles[0][i][2], (0, 0, 255), 3, cv2.LINE_AA)
cv2.circle(cimg, (circles[0][i][0], circles[0][i][1]), 2, (0, 255, 0), 3, cv2.LINE_AA) # draw center of circle
cv2.imshow("source", src)
cv2.imshow("detected circles", cimg)
cv2.waitKey(0)
cv2.imshow("source", src)
cv2.imshow("detected circles", cimg)
cv2.waitKey(0)
......@@ -9,22 +9,24 @@ import numpy as np
import sys
import math
try:
if __name__ == '__main__':
try:
fn = sys.argv[1]
except:
except:
fn = "../data/pic1.png"
print __doc__
src = cv2.imread(fn)
dst = cv2.Canny(src, 50, 200)
cdst = cv2.cvtColor(dst, cv2.COLOR_GRAY2BGR)
print __doc__
src = cv2.imread(fn)
dst = cv2.Canny(src, 50, 200)
cdst = cv2.cvtColor(dst, cv2.COLOR_GRAY2BGR)
if True: # HoughLinesP
if True: # HoughLinesP
lines = cv2.HoughLinesP(dst, 1, math.pi/180.0, 40, np.array([]), 50, 10)
a,b,c = lines.shape
for i in range(a):
cv2.line(cdst, (lines[i][0][0], lines[i][0][1]), (lines[i][0][2], lines[i][0][3]), (0, 0, 255), 3, cv2.LINE_AA)
else: # HoughLines
else: # HoughLines
lines = cv2.HoughLines(dst, 1, math.pi/180.0, 50, np.array([]), 0, 0)
a,b,c = lines.shape
for i in range(a):
......@@ -38,6 +40,6 @@ else: # HoughLines
cv2.line(cdst, pt1, pt2, (0, 0, 255), 3, cv2.LINE_AA)
cv2.imshow("source", src)
cv2.imshow("detected lines", cdst)
cv2.waitKey(0)
cv2.imshow("source", src)
cv2.imshow("detected lines", cdst)
cv2.waitKey(0)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment