コード例 #1
0
def getBarcode(showImage = False):
	camera_index = 0
	capture = cv.CaptureFromCAM(camera_index)
	time.sleep(0.1)

	frame = cv.QueryFrame(capture)
	if(showImage == True):
		cv.imshow('Test image', frame)
	width = frame.width
	height = frame.height
	raw = frame.tostring()

	# wrap image data
	image = zbar.Image(width, height, 'Y800', raw)

	# create a reader
	scanner = zbar.ImageScanner()

	# configure the reader
	scanner.parse_config('enable')
	# scan the image for barcodes
	scanner.scan(image)

	# extract results
	for symbol in image:
	    # do something useful with results
	    print 'decoded', symbol.type, 'symbol', '"%s"' % symbol.data
	return image[0].data
    def render_deepdreamvideo():
        import cv
        print("CV is working")
        cap = cv.VideoCapture('SampleFile.mkv')
        while (cap.isOpened()):
            ret, frame = cap.read()

            gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)

            cv.imshow('frame', gray)
            if cv.waitKey(1) & 0xFF == ord('q'):
                break

        cap.release()
        cv.destroyAllWindows()
コード例 #3
0
def main(argv):
    default_file = 'images/board.JPEG'
    filename = argv[0] if len(argv) > 0 else default_file
    # Loads an image
    src = cv.imread(cv.samples.findFile(filename), cv.IMREAD_GRAYSCALE)
    # Check if image is loaded fine
    if src is None:
        print('Error opening image!')
        print('Usage: hough_lines.py [image_name -- default ' + default_file +
              '] \n')
        return -1

    dst = cv.Canny(src, 50, 200, None, 3)

    # Copy edges to the images that will display the results in BGR
    cdst = cv.cvtColor(dst, cv.COLOR_GRAY2BGR)
    cdstP = np.copy(cdst)

    lines = cv.HoughLines(dst, 1, np.pi / 180, 150, None, 0, 0)

    if lines is not None:
        for i in range(0, len(lines)):
            rho = lines[i][0][0]
            theta = lines[i][0][1]
            a = math.cos(theta)
            b = math.sin(theta)
            x0 = a * rho
            y0 = b * rho
            pt1 = (int(x0 + 1000 * (-b)), int(y0 + 1000 * (a)))
            pt2 = (int(x0 - 1000 * (-b)), int(y0 - 1000 * (a)))
            cv.line(cdst, pt1, pt2, (0, 0, 255), 3, cv.LINE_AA)

    linesP = cv.HoughLinesP(dst, 1, np.pi / 180, 50, None, 50, 10)

    if linesP is not None:
        for i in range(0, len(linesP)):
            l = linesP[i][0]
            cv.line(cdstP, (l[0], l[1]), (l[2], l[3]), (0, 0, 255), 3,
                    cv.LINE_AA)

    y = int(round(1536 / 3))
    x = int(round(2048 / 3))
    src = cv.resize(cdst, (x, y))  # Resize image
    cdst = cv.resize(cdst, (x, y))  # Resize image
    cdstP = cv.resize(cdstP, (x, y))  # Resize image

    cv.imshow("Source", src)
    cv.imshow("Detected Lines (in red) - Standard Hough Line Transform", cdst)
    cv.imshow("Detected Lines (in red) - Probabilistic Line Transform", cdstP)

    cv.imwrite("./houghLines.png", cdstP)

    cv.waitKey()
    return 0
コード例 #4
0
video = cv.VideoCapture(0)

background=0

for i in range(30):
    ret,background=video.read()

background=np.flip(background, axis=1m)



while True:
    ret,img=video.read()
    img=np.flip(img, axis=1)
    hsv=cv.cvtColor(img, cv.COLOR_BGR2HSV)
    blur=cv.GaussianBlur(hsv, (35,35), 0)
    cv.imshow("Display", img)

    lower=np.array([0,120,70])
    upper=np.array([10,255,255])
    mask01=cv.inRange(hsv, lower, upper)

    cv.imshow("Background", background)
    cv.imshow("mask01", mask01)
    k=cv.waitKey(1)
    if k==ord('q'):
        break

video.release()
cv.destroyAllWindows()
import cv as cv
import numpy as np
img = np.zeros((512, 512, 3), np.uint8)
# 填充像素
img.fill(64)
text = "OpenCV for Python"
cv.putText(img, text, (10,40),cv.FONT_HERSHEY_SIMPLEX,\
           1,(0,255,255),1,cv.LINE_AA)
cv.putText(img, text, (10,80),cv.FONT_HERSHEY_PLAIN,\
           1,(0,255,255),2,cv.LINE_AA)
cv.putText(img, text, (10,120),cv.FONT_HERSHEY_DUPLEX,\
           1,(0,255,255),1,cv.LINE_AA)
cv.putText(img, text, (10,160),cv.FONT_HERSHEY_COMPLEX,\
           1,(0,255,255),2,cv.LINE_AA)
cv.putText(img, text, (10,200),cv.FONT_HERSHEY_TRIPLEX,\
           1,(0,255,255),1,cv.LINE_AA)
cv.putText(img, text, (10,240),cv.FONT_HERSHEY_COMPLEX_SMALL,\
           1,(0,255,255),2,cv.LINE_AA)
cv.putText(img, text, (10,280),cv.FONT_HERSHEY_SCRIPT_SIMPLEX,\
           1,(0,255,255),1,cv.LINE_AA)
cv.putText(img, text, (10,320),cv.FONT_HERSHEY_SCRIPT_COMPLEX,\
           1,(0,255,255),2,cv.LINE_AA)
cv.imshow('imgae', img)
cv.waitKey()
cv.destroyAllWindows()
import cv as cv2
# Loading the cascades
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')


# Defining a function that will do the detections
def detect(gray, frame):
    faces = face_cascade.detectMultiScale(gray, 1.3, 5)
    for (x, y, w, h) in faces:
        cv2.rectangle(frame, (x, y), (x + w, y + h), (255, 0, 0), 2)
        roi_gray = gray[y:y + h, x:x + w]
        roi_color = frame[y:y + h, x:x + w]
        eyes = eye_cascade.detectMultiScale(roi_gray, 1.1, 3)
        for (ex, ey, ew, eh) in eyes:
            cv2.rectangle(roi_color, (ex, ey), (ex + ew, ey + eh), (0, 255, 0),
                          2)
    return frame


# Doing some Face Recognition with the webcam
video_capture = cv2.VideoCapture(0)
while True:
    _, frame = video_capture.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    canvas = detect(gray, frame)
    cv2.imshow('Video', canvas)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
video_capture.release()
cv2.destroyAllWindows()
コード例 #7
0
ファイル: circlefind.py プロジェクト: srli/Circles
import cv as cv2
import numpy as np

img = cv2.imread('opencv_logo.png', 0)
img = cv2.medianBlur(img, 5)
cimg = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)

circles = cv2.HoughCircles(img,
                           cv2.HOUGH_GRADIENT,
                           1,
                           20,
                           param1=50,
                           param2=30,
                           minRadius=0,
                           maxRadius=0)

circles = np.uint16(np.around(circles))
for i in circles[0, :]:
    # draw the outer circle
    cv2.circle(cimg, (i[0], i[1]), i[2], (0, 255, 0), 2)
    # draw the center of the circle
    cv2.circle(cimg, (i[0], i[1]), 2, (0, 0, 255), 3)

cv2.imshow('detected circles', cimg)
cv2.waitKey(0)
cv2.destroyAllWindows()
コード例 #8
0
import cv, cv2



img = cv.imread("cones_plus_shadowed_barrel.jpg", cv2.CV_LOAD_IMAGE_COLOR)
cv.namedWindow('Normal Image')
cv.imshow('Normal Image', img)
hsv_img = img
cv.CvtColor(img,hsv_img,cv.CV_RGB2HSV)
cv.namedWindow('HSV Image')
cv.imshow('HSV Image', hsv_img)


cv.waitKey(0)
cv.destroyAllWindows()



コード例 #9
0
import cv
import time
import numpy as np

cv_car = cv.CascadeClassifier(
    r'C:\Users\DEBIPRASAD\Desktop\Projetc Work\ComputerVision-Projects-master\CarPedestrianDetection\cascades\haarcascade_car.xml'
)
capture = cv.VideoCapture(
    r'C:\Users\DEBIPRASAD\Desktop\Projetc Work\ComputerVision-Projects-master\CarPedestrianDetection\files\cars.avi'
)

while capture.isOpened():
    response, frame = capture.read()
    if response:
        gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
        cars = cv_car.detectMultiScale(gray, 1.2, 3)
        for (x, y, w, h) in cars:
            cv.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 0), 3)
            cv.imshow('cars', frame)
        if cv.waitkey(1) & 0xFF == ord('q'):
            break
    else:
        break
capture.release()
cv.destroyAllWindows()
コード例 #10
0
ファイル: circlefind.py プロジェクト: srli/Circles
import cv as cv2
import numpy as np

img = cv2.imread('opencv_logo.png',0)
img = cv2.medianBlur(img,5)
cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)

circles = cv2.HoughCircles(img,cv2.HOUGH_GRADIENT,1,20,
                            param1=50,param2=30,minRadius=0,maxRadius=0)

circles = np.uint16(np.around(circles))
for i in circles[0,:]:
    # draw the outer circle
    cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)
    # draw the center of the circle
    cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),3)

cv2.imshow('detected circles',cimg)
cv2.waitKey(0)
cv2.destroyAllWindows()
コード例 #11
0
ファイル: camera_stream.py プロジェクト: yumion/onodera-lab
# capture frames from the camera
for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
    # grab the raw NumPy array representing the image, then initialize the timestamp
    # and occupied/unoccupied text
    image = frame.array

    gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)

    faces = faceCascade.detectMultiScale(
        gray,
        scaleFactor=1.1,
        minNeighbors=5,
        minSize=(30, 30),
        flags=cv.CASCADE_SCALE_IMAGE
    )

    # Draw a rectangle around the faces
    for (x, y, w, h) in faces:
        cv.rectangle( image, (x, y), (x+w, y+h), (0, 255, 0), 2)

    # show the frame
    cv.imshow("Frame", image)
    key = cv.waitKey(1) & 0xFF

    # clear the stream in preparation for the next frame
    rawCapture.truncate(0)

    # if the `q` key was pressed, break from the loop
    if key == ord("q"):
        break
コード例 #12
0
ファイル: 421.py プロジェクト: sahareslami/Computer-Vision
a_separate_r_log_normalize = normalize(a_separate_r_log)

# resize filters to show
a_separate_c_log_f = cv.resize(a_separate_c_log_normalize, (512, 512))
a_separate_r_log_f = cv.resize(a_separate_r_log_normalize, (512, 512))
a_log = cv.resize(a_log_normalize, (512, 512))
b_log = cv.resize(b_log_normalize, (512, 512))
c_log = cv.resize(c_log_normalize, (512, 512))

# write filters
cv.imwrite(out_path + 'a.jpg', a_log)
cv.imwrite(out_path + 'b.jpg', b_log)
cv.imwrite(out_path + 'c.jpg', c_log)
cv.imwrite(out_path + 'a_separate_c.jpg', a_separate_c_log_f)
cv.imwrite(out_path + 'a_separate_r.jpg', a_separate_r_log_f)
'''
# read filters
a_fft = cv.imread('a.jpg', 0)
b_fft = cv.imread('b.jpg', 0) 
c_fft = cv.imread('c.jpg', 0) 
a_separate_c_fft = cv.imread('a_separate_c.jpg', 0)
a_separate_r_fft = cv.imread('a_separate_r.jpg', 0)

# show filters
cv.imshow('a', a_fft)
cv.imshow('b', b_fft)
cv.imshow('c', c_fft)
cv.imshow('a_separate_c',a_separate_c_fft)
cv.imshow('a_separate_r',a_separate_r_fft)
'''