コード例 #1
0
 def __init__(self):
     self.start = datetime.now()
     self.cap = Camera([0], fps=30, resolution=Camera.RES_LARGE, colour=True, auto_gain=True, auto_exposure=True, auto_whitebalance=True)
     # self.cap = cv2.VideoCapture(0)
     self.laby = []
     self.frame = 0
     self.l_bg = None
     self.width = 1280
     self.height = 720
     self.l_average = 0
     self.l_frame = None
     self.grid = None
     self.mask = None 
     self.f_num = 0
     self.fourcc = cv2.VideoWriter_fourcc(*'MJPG')
     self.out = cv2.VideoWriter('video_out/cc.avi', self.fourcc, 20.0, (self.width,self.height))
コード例 #2
0
 def __init__(self):
     self.start = datetime.now()
     self.cap = Camera([0],
                       fps=30,
                       resolution=Camera.RES_LARGE,
                       colour=True,
                       auto_gain=True,
                       auto_exposure=True,
                       auto_whitebalance=True)
     self.laby = []
     self.l_bg = None
     self.width = 1280
     self.height = 720
     self.l_average = 0
     self.l_frame = None
     self.grid = None
     self.mask = None
コード例 #3
0
ファイル: acq.py プロジェクト: bensondaled/video_recording
# expt name
expt_name = input('\nEnter unique experiment name:\n').replace('/', '-')
exp_data_dir = os.path.join(data_dir, expt_name)
if os.path.exists(exp_data_dir):
    cont = input(
        '\nExperiment folder with this name already exists.\nAre you sure you want to continue? (y/n)\n'
    )
    if cont != 'y':
        quit()
os.makedirs(exp_data_dir, exist_ok=True)

# setup camera
assert cam_count(
) > 0, '\n\nCamera not detected. Is it plugged into the computer? If so, trying unplugging and replugging, then run again.\n\n\n'
cam = Camera(resolution=resolution, fps=fps)

# main loop
ans = ''
dur = 10  # random default
used_ids = []
while True:
    ans = input(
        "\nMain menu:\n\t'r' to record\n\t'd' to display\n\t'reset' to reset camera\n\t'q' to quit\n"
    )

    if ans == 'q':
        break

    elif ans == 'd':
        # inspect camera
コード例 #4
0
    refresh2d(width, height)
    glColor3f(0.2, 0.2, 0.2)
    find_mz()
    draw_mz(mz)
    glutSwapBuffers()


global mz
global start
global width
global height
global processing
global cap
processing = False
window = 0
start = datetime.now()
cap = Camera([0], fps=30, resolution=Camera.RES_LARGE, colour=False)
find_mz()
width = 1400
height = 880

glutInit()
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH)
glutInitWindowSize(width, height)
glutInitWindowPosition(0, 0)
glutSetCursor(GLUT_CURSOR_NONE)
window = glutCreateWindow("test")
glutDisplayFunc(draw)
glutIdleFunc(draw)
glutMainLoop()
コード例 #5
0
from pseyepy import Camera, Stream, Display
import cv2
import numpy as np
from cv2 import aruco
from cv2 import Rodrigues
from math import sqrt
import matplotlib.pyplot as plt

c = Camera([0, 1], resolution=[Camera.RES_LARGE, Camera.RES_LARGE])
#c = Camera(resolution = [Camera.RES_LARGE])
#c.exposure = 23

#frame, timestamp = c.read(0)
#frame2, t2 = c.read(1)

#matType = cv2.CV_8UC3;
#test = cv2.CreateMat(480, 640, matType, frame)

#test = np.array(frame,copy = True)
#gray = cv2.cvtColor(test, cv2.COLOR_BGR2GRAY)

#test2 = np.array(frame2,copy = True)
#gray2 = cv2.cvtColor(test2, cv2.COLOR_BGR2GRAY)

#cv2.imshow("test",gray)
#cv2.imshow("test2",gray2)
#print(test)

#d = Display(c)
#s = Stream(c, file_name='example_movie.avi', display=True,codec='png') # begin saving data to files
#s.end()
コード例 #6
0
def main(cam, show, pseye):
    global processing
    if pseye == 1:
        cap = Camera([0], fps=60, resolution=Camera.RES_LARGE, colour=False)
        frame, timestamp = cap.read()
        # width, height = frame.shape
    else:
        cap = cv2.VideoCapture(cam)
    sz = 80
    run = True
    vals = {}

    tiles = []

    mz = cv2.imread("live_full_mz/live_full_mz.png")
    c = 1
    last_diff = 0

    # cv2.namedWindow("mz", cv2.WND_PROP_FULLSCREEN)
    # cv2.setWindowProperty("mz", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)

    if show == 0:
        window = False
    else:
        window = True
    while (run):
        try:
            if pseye == 1:
                frame, timestamp = cap.read()
            else:
                ret, frame = cap.read()
            small = cv2.resize(frame, (0, 0), fx=0.18, fy=0.18)
            width, height = small.shape
            ret, thr = cv2.threshold(small, 1, 255,
                                     cv2.THRESH_BINARY + cv2.THRESH_OTSU)
            kernel = np.ones((1, 1), np.uint8)
            opening = cv2.morphologyEx(thr,
                                       cv2.MORPH_OPEN,
                                       kernel,
                                       iterations=2)
            bg = cv2.dilate(opening, kernel, iterations=3)

            if not processing:
                processing = True
                tiles = processTiles(width, height, sz, bg)
                for tile in tiles:
                    tile = np.array(tile)

            if window:
                # cv2.imshow('cam', bg)
                for i, tile in enumerate(tiles):
                    cv2.imshow(('%s' % i), tile)

            k = cv2.waitKey(1)
            if k == ord('q'):
                run = False
            c += 1
        except Exception as e:
            print(e)
            pass
    # program closing, stop camera stream and close windows
    if pseye == 1:
        cap.end()
    else:
        cap.release()
    cv2.destroyAllWindows()
コード例 #7
0
import cv2
import numpy as np
from pseyepy import Camera, Display

c = Camera([0], fps=60, resolution=Camera.RES_LARGE, colour=True)

# print("frame: {}, time: {}".format(frame, timestamp))
# d = Display(c)

run = True

frame, timestamp = c.read()

cv2.namedWindow("mz", cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty("mz", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
cv2.setWindowProperty("mz", cv2.WND_PROP_ASPECT_RATIO, cv2.WINDOW_FREERATIO)

while run:

    # im = np.array(frame)

    frame, timestamp = c.read()
    # width, height = frame.shape

    frame = frame[100:320, 100:540]

    # b,g,r = cv2.split(im)
    cv2.imshow("mz", frame)
    # cv2.imshow("R", r)
    # cv2.imshow("G", g)
    # cv2.imshow("B", b)
コード例 #8
0
ファイル: server.py プロジェクト: plotguy/plotguy
 def __init__(self):
     self.camera = Camera()
コード例 #9
0
ファイル: run.py プロジェクト: bensondaled/neu350
##

import os
from pseyepy import Camera, Stream, Display

path = '/Users/ben/Desktop'
file_name = '20180107_crayfish0'
file_name += os.path.join(path, file_name + '.avi')

##

c = Camera([0, 1], resolution=Camera.RES_LARGE, fps=15)
d = Display(c)

##

s = Stream(c, file_name=file_name, codec='png')

##

s.end()
c.end()

##
コード例 #10
0
def main(cam, show, pseye):
    if pseye == 1:
        cap = Camera([0], fps=60, resolution=Camera.RES_LARGE, colour=False)
        # frame, timestamp  = cap.read()
        # width, height = frame.shape
    else:
        cap = cv2.VideoCapture(cam)
        # width = floor(cap.get(3)) // 2
        # height = floor(cap.get(4)) // 2
    # sz = 100
    run = True
    # vals = {}
    mz = cv2.imread("live_full_mz/live_full_mz.png")
    # mz_sm =  cv2.resize(mz, (0,0), fx=0.3, fy=0.3)
    global processing
    c = 1
    # last_diff = 0

    cv2.namedWindow("mz", cv2.WND_PROP_FULLSCREEN)
    cv2.setWindowProperty("mz", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
    cv2.setWindowProperty("mz", cv2.WND_PROP_ASPECT_RATIO,
                          cv2.WINDOW_FREERATIO)

    if show == 0:
        window = False
    else:
        window = True
    while (run):
        try:
            if pseye == 1:
                frame, timestamp = cap.read()
                # width, height = frame.shape
            else:
                ret, frame = cap.read()

            frame = frame[100:320, 100:540]
            small = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
            # gray = cv2.cvtColor(small,cv2.COLOR_BGR2GRAY)
            ret, thr = cv2.threshold(small, 1, 255,
                                     cv2.THRESH_BINARY + cv2.THRESH_OTSU)
            kernel = np.ones((1, 1), np.uint8)
            opening = cv2.morphologyEx(thr,
                                       cv2.MORPH_OPEN,
                                       kernel,
                                       iterations=1)
            bg = cv2.dilate(opening, kernel, iterations=2)

            # if c < 50:
            if not processing:
                # diff = detect_diffs_two(vals, c, width, height, sz, bg)
                # print(diff - last_diff)
                # d_sum = diff - last_diff
                # if d_sum > 0.005 or d_sum < -0.005:
                processing = True
                mz = processFrame(bg)
                try:
                    mz = np.array(mz)
                    # mz = cv2.resize(mz, (0, 0), fx=4, fy=4)
                except Exception as e:
                    print(e)
                    pass
                    # mz = cv2.imread("live_full_mz/live_full_mz.png")

                    # last_diff = diff
                    # mz_sm =  cv2.resize(mz, (0,0), fx=0.3, fy=0.3)
                    # mz - cv2.imread("live_full/", 1)
                    #  detect_diffs(vals, c, width, height, sz, bg)
                    # print("----")

            if window:
                try:
                    # cv2.imshow('cam', bg)
                    cv2.imshow('mz', mz)
                except Exception as e:
                    print(e)
                    pass
            k = cv2.waitKey(1)
            # if k == ord('+'):
            #     mz = cv2.resize(mz, (0,0), fx=1.1, fy=1.1)
            # if k == ord('-'):
            #     mz = cv2.resize(mz, (0,0), fx=0.9, fy=0.9)
            if k == ord('q'):
                run = False
            c += 1
        except Exception as e:
            print(e)
            pass
    if pseye == 1:
        cap.end()
    else:
        cap.release()
    cv2.destroyAllWindows()