示例#1
0
def test_image_grabber():
    """
    This is just a photo-booth type of demo
    It does not really pass/fail.  You need to check
    in the folder and see if it captures 4 or 5 images.
    And that it writes to the log file.
    INFO:unit_test:Call 5: captured image to camera_capture_001.jpg, result was [Result is 4]
    INFO:unit_test:Call 10: captured image to camera_capture_002.jpg, result was [Result is 9]
    INFO:unit_test:Call 15: captured image to camera_capture_003.jpg, result was [Result is 14]
    INFO:unit_test:Call 20: captured image to camera_capture_004.jpg, result was [Result is 19]
    """
    cap = cv2.VideoCapture(-1)
    cap.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, 320);
    cap.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, 240);
    cap.set(cv2.cv.CV_CAP_PROP_FPS, 30)

    ig = ImageGrabber(logger, 5, 5)

    for i in range(30):
        # get an image
        ret, frame = cap.read()

        result = "Result is {:d}".format(i)
        ig.grab(frame, result)

        sleep(1)
示例#2
0
 def __init__(self, sending_queue, stop_dict, cfg, ext_ratio=0.1):
     super(PreparingService, self).__init__()
     self.cfg = cfg
     self.device_id = get_mac()
     self.lp_detector = LicensePlateDetector(cfg.yolo_model)
     self.segmentation = SegmentCharacter()
     self.sending_queue = sending_queue
     self.image_grabber = ImageGrabber(cfg.camera.url, cfg.camera.usb)
     self.image_grabber.start()
     self.ext_ratio = ext_ratio
     self.stop_dict = stop_dict
示例#3
0
    im_show = True
    sliders = True
    printer = True
    wait = False
else:
    im_show = False
    sliders = False
    printer = False
    wait = False

MIN_AREA = 500

logging.basicConfig(level=logging.INFO,format='%(asctime)s %(message)s',filename="/var/log/vision.log")
logger = logging.getLogger(__name__)

grabber = ImageGrabber(logger, grab_period=1, grab_limit=1300)

def set_thresholds(target_color):
    global lower_h, lower_s, lower_v
    global upper_h, upper_s, upper_v
    if target_color == "red":
        print("Setting target color to red")
        lower_h = 60
        upper_h = 180
        lower_s = 0
        upper_s = 70
        lower_v = 110
        upper_v = 255
    else:
        print("Setting target color to blue")
        lower_h = 85
示例#4
0
class PreparingService(threading.Thread):
    def __init__(self, sending_queue, stop_dict, cfg, ext_ratio=0.1):
        super(PreparingService, self).__init__()
        self.cfg = cfg
        self.device_id = get_mac()
        self.lp_detector = LicensePlateDetector(cfg.yolo_model)
        self.segmentation = SegmentCharacter()
        self.sending_queue = sending_queue
        self.image_grabber = ImageGrabber(cfg.camera.url, cfg.camera.usb)
        self.image_grabber.start()
        self.ext_ratio = ext_ratio
        self.stop_dict = stop_dict

    def run(self):
        while not self.stop_dict["PreparingService"]:
            try:
                if not self.image_grabber.stop:
                    image = self.image_grabber.get_frame()
                    bboxes, labels, conf_scores = self.lp_detector.detect(
                        image)
                    # Coordinate of characters in a license plate
                    char_coords = []
                    # Coordinate of license plate
                    coord_boxes = []
                    for i, bbox in enumerate(bboxes):
                        conf_score = conf_scores[i]
                        coord_box = [int(val) for val in bbox]

                        width = coord_box[2] - coord_box[0]
                        height = coord_box[3] - coord_box[1]
                        coord_box[0] = max(
                            0, int(coord_box[0] - width * self.ext_ratio))
                        coord_box[1] = max(
                            0, int(coord_box[1] - height * self.ext_ratio))
                        coord_box[2] = min(
                            image.shape[1],
                            int(coord_box[2] + width * self.ext_ratio))
                        coord_box[3] = min(
                            image.shape[0],
                            int(coord_box[3] + height * self.ext_ratio))

                        lp_image = image[coord_box[1]:coord_box[3],
                                         coord_box[0]:coord_box[2]]
                        # print(lp_image.shape)
                        processing_time = time.time()
                        char_coord_perbox = self.segmentation.segment(lp_image)
                        # print("Processing time:", time.time() - processing_time)

                        if len(char_coord_perbox) > 0 and len(
                                char_coord_perbox) <= 10:
                            char_coord_perbox = pad_or_truncate(
                                char_coord_perbox, 10)
                            coord_boxes.append(coord_box)
                            char_coords.append(char_coord_perbox)

                    package = pickle.dumps({
                        "image": image,
                        "coord_boxes": coord_boxes,
                        "char_coords": char_coords,
                        "deviceID": self.device_id
                    })
                    self.sending_queue.put(package)
            except Exception as e:
                print(str(e))
        self.image_grabber.stop = True
        self.image_grabber.join()
示例#5
0
    data, address = sock.recvfrom(4096)
    if (data == "Toggle Interactive Mode") and imshow:
        restart_program("not_interactive")
    else:
        restart_program("127.0.0.1", "interactive")
    if data:
        sent = sock.sendto(data, address)


logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s', filename="/var/log/vision.log")
logger = logging.getLogger(__name__)

logger.info("********** Vision Startup **********")

if grabbing:
    grabber = ImageGrabber(logger, grab_period=grab_period, grab_limit=4000)

# Make a UDP Socket
# try:
#     sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
#     server_address = ('localhost', 10000)
#     sock.bind(server_address)
# except:
#     print("Crap")

# These are the hue saturation value
# This works for close-up
exposure = 30
lower_h = 75
lower_s = 100
lower_v = 100
示例#6
0
import pandas as pd
from PIL import Image
from datetime import datetime, timedelta
import pytesseract
import logging
import time
sys.path.append('/usr/local/lib/python3.5/dist-packages/pytesseract/')

#path1 = 'C:/Users/anurag/Documents/Python Scripts/RadarImages/server/'
path1='/home/sanand/radar/'
os.chdir(path1)

from image_processing import ImageProcessing
from image_grabber import ImageGrabber
processor = ImageProcessing()
grabber = ImageGrabber()

# Setting Logger
logger = logging.getLogger('radar_60')
hdlr = logging.FileHandler(path1 + '/logs/radar_60.log')
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.INFO)
logger.info('Started')

# Setting Timezone
os.environ["TZ"] = "Asia/Kolkata"
time.tzset() 
logger.info('Timezone Set: {}'.format(datetime.now()))
示例#7
0
            warped = cv2.warpAffine(img,
                                    M, (image_size[1], image_size[0]),
                                    borderValue=0.0)
            return warped


if __name__ == "__main__":
    import anyconfig
    import munch
    from image_grabber import ImageGrabber
    import cv2
    opt = anyconfig.load("settings.yaml")
    opt = munch.munchify(opt)

    detector = FaceDetector(opt.face_detector.model_path, -1)
    imageGrabber = ImageGrabber(opt.camera.url, opt.camera.fps,
                                opt.camera.push2queue_freq, opt.camera.rgb)
    imageGrabber.start()
    fps = FPS().start()
    while not imageGrabber.stop:
        image = imageGrabber.get_frame()
        bboxes, points = detector.detect(image, 1.0)
        # Comment this stuff if you want to test FPS
        aligned_faces = []
        for i, bbox in enumerate(bboxes):
            conf_score = bbox[4]
            coords_box = [int(val) for val in bbox[:4]]
            if conf_score < 0.5:
                continue
            x_min, y_min, x_max, y_max = coords_box
            for point in points[i]:
                cv2.circle(image, (point[0], point[1]), 1, (0, 255, 0), 3)
示例#8
0
    printer = True
    wait = False
else:
    im_show = False
    sliders = False
    printer = False
    wait = False

MIN_AREA = 500

logging.basicConfig(level=logging.INFO,
                    format='%(asctime)s %(message)s',
                    filename="/var/log/vision.log")
logger = logging.getLogger(__name__)

grabber = ImageGrabber(logger, grab_period=1, grab_limit=1300)


def set_thresholds(target_color):
    global lower_h, lower_s, lower_v
    global upper_h, upper_s, upper_v
    if target_color == "red":
        print("Setting target color to red")
        lower_h = 60
        upper_h = 180
        lower_s = 0
        upper_s = 70
        lower_v = 110
        upper_v = 255
    else:
        print("Setting target color to blue")
示例#9
0
import pandas as pd
from PIL import Image
from datetime import datetime, timedelta
import pytesseract
import logging
import time
import pymysql
sys.path.append('/usr/local/lib/python3.5/dist-packages/pytesseract/')
#path1 = '/Users/sagar_paithankar/Desktop/image_recognition/Delhi_meteo/'
path1 = '/root/radar/delhi/meteo/'
os.chdir(path1)

from image_processing import ImageProcessing
from image_grabber import ImageGrabber
processor = ImageProcessing()
grabber = ImageGrabber()

# Setting Logger
logger = logging.getLogger('meteo')
hdlr = logging.FileHandler(path1 + '/logs/meteo.log')
formatter = logging.Formatter(
    '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.INFO)
logger.info('Started')

# Setting Timezone
os.environ["TZ"] = "Asia/Kolkata"
time.tzset()
logger.info('Timezone Set: {}'.format(datetime.now()))