예제 #1
0
 def initCamera(self):
     try:
         self.cam = ids.Camera()
         self.cam.color_mode = ids.ids_core.COLOR_RGB8  # Get images in RGB format
         self.cam.auto_exposure = True
         self.cam.continuous_capture = True  # Start image capture
         return self.OP_OK
     except:
         return self.OP_ERR
예제 #2
0
def main():
    #
    # Sync the clock.
    #
    sync_time()

    #
    # get our vehicle
    #
    #api = local_connect()
    #vehicle = api.get_vehicles()[0]

    #
    # Get the camera
    #
    dev = ids.Camera()
    dev.continuous_capture = False

    #
    # Configure the camera
    #
    #dev.pixelclock = dev.pixelclock_range[1]
    dev.auto_white_balance = False
    dev.color_mode = ids.ids_core.COLOR_RGB8
    exposure_us = 100000
    dev.auto_exposure = False
    dev.exposure = exposure_us * 1e-3
    dev.gain = 0

    #
    # Start capturing images
    #
    dev.continuous_capture = True
    while True:
        print 'Capturing Image'
        t = datetime.now()
        base_name = os.path.join(
            BASE_FOLDER,
            t.strftime("/home/odroid/test_imgs/%Y%m%d_%H:%M:%S.%f"))
        img_name = base_name + '.jpg'
        data_name = base_name + '.txt'

        dev.next_save(img_name)

        data = {
            "img_path": img_name,
            "Time": t.strftime("%Y%m%d_%H:%M:%S.%f"),
            "Exposure": dev.exposure,
            #"location": str(vehicle.location)
        }

        with open(data_name, 'w') as f:
            json.dump(data, f)

    dev.continuous_capture = False
예제 #3
0
    def __init__(self):
        import ids

        self._cam = ids.Camera(nummem=1)

        self._cam.auto_white_balance = False
        self._cam.continuous_capture = False
        self._cam.auto_exposure = False
        self._cam.exposure = 100
        self._cam.color_mode = ids.ids_core.COLOR_BAYER_8
        self._cam.gain_boost = False
        self._cam.gain_db = 0
예제 #4
0
def start_cam(ida, expo=0, pixelclock=24):
    # turn on cam, note default exposure time and pixelclock
    # what should color mode be?
    cam = ids.Camera(ida)
    cam.color_mode = ids.ids_core.COLOR_RGB8  # preview blue, saved yellow
    #cam.color_mode = ids.ids_core.COLOR_BGR8 # preview yellow, saved blue
    cam.pixelclock = pixelclock  # reduce pxclock to increase expo
    if expo > 0:
        cam.exposure = expo
    elif expo == 0:
        cam.exposure = 50
        #cam.auto_exposure = True
    return cam
예제 #5
0
    def __init__(self, callback=None):

        try:
            import ids
            globals()['ids'] = ids

            self.capture_dev = ids.Camera(nummem=10)

            #
            # Turn off white balance.
            #
            self.capture_dev.auto_white_balance = False

            #
            # Image callback.
            #
            self._callback = callback

        except Exception as e:
            logging.exception(
                'Error while initializing the camera:\n{}'.format(repr(e)))
            raise CameraException('Failed initializing the camera')

        #
        # set the color mode map
        #
        self._ids_color_map = {
            gs.COLOR_RAW: ids.ids_core.COLOR_BAYER_8,
            gs.COLOR_RGB: ids.ids_core.COLOR_RGB8
        }

        #
        # Last exposure used for checking if there is a need
        # to throw the next image.
        #
        self._last_settings = None
예제 #6
0
print('Initializing camera.')

print('%d cycles with %d s between cycles. Each cycle %d frames.' %
      (Nc, wait_time_s, Nt))
print('Total number of acquisition %d (%.2f hours).' %
      (Nc * Nt, Nc * Nt * wait_time_s / 3600.))
print('Exposure time %d ms.' % exposure)

on = 100
off = 0
p.start(off)
n = 0
while n < Nc:
    start = time.clock()
    time.sleep(1)
    cam = ids.Camera()
    cam.color_mode = ids.ids_core.COLOR_MONO_8
    cam.exposure = exposure  #in ms
    ft = ids.ids_core.FILETYPE_PNG
    cam.continuous_capture = True
    time.sleep(2)
    p.ChangeDutyCycle(on)

    for t in range(Nt):
        filename = name_template % (n, t)
        cam.next_save(
            filename, filetype=ft,
            quality=100)  # first two images often corrupted... a bug?
        cam.next_save(filename, filetype=ft, quality=100)
        print('%d/%d %s' % (n * Nt + t + 1, Nc * Nt, filename))
        cam.next_save(filename, filetype=ft, quality=100)
예제 #7
0
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
import ids
exposure = 3  #in ms
name_template = 'cycle%03d_t%03d.png'
cam = ids.Camera(handle=1)
#cam.color_mode = ids.ids_core.COLOR_MONO_8
cam.exposure = exposure  #in ms
ft = ids.ids_core.FILETYPE_PNG
cam.continuous_capture = True

img, meta = cam.next()
img, meta = cam.next()
img, meta = cam.next()

if img.ndim > 2:
    img = img[:, :, 0]

cent = (img.shape[0] / 2, img.shape[1] / 2)
avg = img.mean()

plt.ion()
plt.figure()
plt.imshow(img[cent[0] - 128:cent[0] + 127, cent[1] - 128:cent[1] + 127])
plt.title('Center ROI')
plt.show()

plt.figure()
a = plt.hist(img.ravel(), bins=256, range=(0, 256))
plt.title('Histogram of intensities, mean = %d' % avg)
예제 #8
0
        lines = temp_raw()
    temp_output = lines[1].find('t=')

    if temp_output != -1:
        temp_string = lines[1].strip()[temp_output + 2:]
        temp_c = float(temp_string) / 1000.0
        return temp_c


n = 0
while n < Nc:
    start = time.clock()
    p.ChangeDutyCycle(LED_on)
    time.sleep(1)

    cam1 = ids.Camera()
    serial_num1 = cam1.info['serial_num']
    if not os.path.exists(serial_num1):
        os.makedirs(serial_num1)
    cam1.color_mode = ids.ids_core.COLOR_MONO_8
    cam1.exposure = exposure  #in ms

    cam2 = ids.Camera()
    serial_num2 = cam2.info['serial_num']
    if not os.path.exists(serial_num2):
        os.makedirs(serial_num2)
    cam2.color_mode = ids.ids_core.COLOR_MONO_8
    cam2.exposure = exposure  #in ms

    cam1.continuous_capture = True
    for t in range(Nt):
예제 #9
0
파일: test_ueye_xc.py 프로젝트: crishoj/ids
 def setUp(self):
     super().setUp()
     self.cam = ids.Camera(handle=HANDLE, color=COLOR)
예제 #10
0
def cam_deffect_detection():
    detectionOn = str(raw_input('Deffect detection mode: (on/off)')) or 'on'
    if detectionOn == 'on':
        print('Detection mode: ON')
    elif detectionOn == 'off':
        print('Detection mode: OFF')
    else:
        print('Input not recognized, not gonna detect.')
    stopMachineOn = str(raw_input('Stop machine mode: (on/off)')) or 'on'
    if stopMachineOn == 'on':
        print('Stop mode: ON')
        output_port = int(raw_input('RPi low voltage GPIO port: (27)')) or 27
    elif stopMachineOn == 'off':
        print('Stop mode: OFF')
    else:
        print('Input not recognized, not gonna stop.')
    now = datetime.datetime.now()

    cam = ids.Camera()
    cam.color_mode = ids.ids_core.COLOR_RGB8  # Get images in RGB format

    cam.auto_exposure = True
    cam.continuous_capture = True  # Start image capture

    #for shutters in range(115, 150 ,5):
    #for shutters in range(50,60,5):
    #shutters /= 10.
    #cam.exposure = shutters                            # Set initial exposure to 5ms
    directory = 'teste_domingo_migusta/'
    if not os.path.exists(directory):
        os.makedirs(directory)
    #directory2 = 'imagens/%s' %  now.strftime('%Y_%m_%d_%H_%M_%S')
    #if not os.path.exists(directory2):
    #    os.makedirs(directory2)
    #print(shutters)
    N = int(raw_input('Number of photos: ')) or 15
    for i in range(N):
        #path1 = directory2 +'/image%s.jpg' % now.strftime('%Y_%m_%d_%H_%M_%S')
        #camera.capture(path1)
        #print('Saved: ' + path1)
        img, meta = cam.next()  # Get image as a Numpy array
        #pil_img = Image.fromarray(img)
        nome_imagem = 'imagem_%s.jpg' % datetime.datetime.now().strftime(
            '%Y_%m_%d_%H_%M_%S')
        path2 = directory + nome_imagem
        #pil_img.save(path2, quality = 100)

        misc.imsave(path2, img)

        #pil_img.save('teste_domingo_migusta/last_image.jpg', quality = 100)

        misc.imsave('teste_domingo_migusta/last_image.jpg', img)

        print('Saved: ' + path2)

        fabric = {
            '_id': i,
            'defect': 'None',
            'date': datetime.datetime.now(),
            'imageUrl': 'imgs/' + nome_imagem,
            'deviceID': 'GJjybzAy5V'
        }

        if detectionOn == 'on':
            deffect_lycra = funcao_deteccao_lycra_tracadelas(path2)
            deffect_agulha = funcao_detecao_agulhas(path2)

            if stopMachineOn == 'on' and (deffect_lycra[0] or deffect_agulha):

                if deffect_agulha:
                    fabric['defect'] = 'Agulha'
                    print("Defeito agulha!")
                if deffect_lycra[0]:
                    fabric['defect'] = deffect_lycra[1]
                    print("Defeito lycra!")

                GPIO.setmode(GPIO.BCM)
                GPIO.setup(output_port, GPIO.OUT, initial=GPIO.LOW)
                GPIO.output(output_port, GPIO.LOW)
                sleep(1)
                GPIO.setup(output_port, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
                #break

        #db['fabrics'].insert_one(fabric)
        sleep(.8)
예제 #11
0
파일: example.py 프로젝트: galaunay/ids
import ids
from PyQt4 import QtGui
import cv2
import numpy as np
import matplotlib.pyplot as plt
import ids
from ids.gui import IdsQtApp, IdsQtView

with ids.Camera(nummem=2, color=ids.COLOR_MONO_8) as cam:
    #==========================================================================
    # Settings
    #==========================================================================
    cam.color_mode = ids.COLOR_MONO_8  # Get images in RGB format
    # cam.exposure = 5                            # Set initial exposure to 5ms
    cam.auto_exposure = True
    cam.auto_exposure_brightness = True
    # cam.auto_speed = True
    # cam.auto_white_balance = False
    # cam.continuous_capture = True               # Start image capture
    cam.gain = 0
    # cam.height = 600
    # cam.width = 800
    cam.pixelclock = 10

    # #==============================================================================
    # # TMP
    # #==============================================================================
    # cam.continuous_capture = True
    # img, metadata = cam.next()
    # cd = CircleDetector(1)
    # cd.process(img)