def get_strip(frame):
    '''
    Get the strip location with the following steps:
        1. for a given img, find the location of qr code by utilizing the tool QR-Code-Extractor 
        2. find approximate position of the black background
        3. find exact position of the black background
        4. get the strip position
    input: img frame
    output: stripes background area squares, and the processed img contains only stripes background

    :param frame:  img frame
    :return strip_squares: the vertices of rectangle that containing strip
    :return strip_img: img containing only the strip
    '''

    # straighten the img based on the qr code angle
    _, _, _, rotated_img = qe.extract(frame, False)
    # get the qr code position
    frame, qr_square, qr_area, rotated_img = qe.extract(rotated_img, False)

    # get the approximate position of the black background to narrow down the search range
    qr_pos = [qr_square[x][0][:] for x in range(len(qr_square))]
    mask = get_background_mask_from_qr_pos(qr_pos)
    # masked the travail part
    masked_image = region_of_interest(frame.copy(), mask)

    # get the exact position of the black background based on the approximate position and qr_area
    bg_img, bg_squares = get_bg_rectangle(masked_image, qr_area)
    bg_area = cv2.contourArea(bg_squares[0])

    # straighten the img based on the strip angle
    strip_img, _, rotate_strip = get_strip_rectangle(bg_img.copy(), bg_area,
                                                     bg_squares)
    # get the strip position
    strip_img, strip_squares, rotate_strip = get_strip_rectangle(
        rotate_strip, bg_area, bg_squares)

    return strip_squares, strip_img
示例#2
0
import cv2

import qr_extractor as reader

cap = cv2.VideoCapture(0)

while True:
    _, frame = cap.read()
    codes, frame = reader.extract(frame, True)
    cv2.imshow("frame", frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        print("I quit!")
        break

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
示例#3
0
import cv2
import numpy as np
import qr_extractor as reader

# Load image
img = cv2.imread('testimg.jpg')

# Display image

# Extract qr code

codes, frame = reader.extract(img, True)
cv2.imshow('frame', frame)
print len(codes)

cv2.waitKey(0)
# Display



示例#4
0
文件: mlo.py 项目: midiacom/alfa
        while True:
            # Wait for the next frame
            if not video.frame_available():
                continue

            time.sleep(0.1)
            frame = video.frame()
        
            # cv2.imwrite('frame.jpg', frame)

            # remove the comment to show a video frame, not work inside docker container
            # cv2.imshow('frame', frame)
            # if cv2.waitKey(1) & 0xFF == ord('q'):
            #     break

            codes, image_frame = reader.extract(frame, False)

            if len(codes):
                print(1)
                timestamp = datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S-%f')
                ret_code, jpg_buffer = cv2.imencode(
                    ".jpg", image_frame, [int(cv2.IMWRITE_JPEG_QUALITY), jpeg_quality])
                jsondata = {'sensor_id': node_name,
                            'timestamp': timestamp}
                jsonstr = json.dumps(jsondata)

                # Debug
                print("MLO\n", flush=True)
                print(jsonstr, flush=True)

                sender.send_jpg(jsonstr, jpg_buffer)
示例#5
0
# Main loop

# Constants
count = 0
threshold = 24
clearScreen = False

# Aquire webcam capture
webcamID = 1  # 0 for build in webcam, 1 for USB webcam
cap = cv2.VideoCapture(1)

while True:
    count = count + 1

    _, frame = cap.read()  # Read frame from webcam
    codes, frame = reader.extract(frame, True)  # Extract QR codes from
    cv2.imshow("frame", frame)  # Display

    labels = decodeImages(codes)

    # Display data
    if count > threshold:
        if clearScreen:
            cls()
            clearScreen = False
        else:
            print(labels)
            clearScreen = True
        count = 0

    # Quit loop if requested
示例#6
0
'''
Orientation and position of QR
Add into Pi RC_main
'''
import cv2
import qr_extractor as reader

cap = cv2.VideoCapture(0)
# change it to pi USB cam

while True:
    _, frame = cap.read()
    codes, frame, angle_a, angle_b, center = reader.extract(frame, True)
    cv2.imshow("frame", frame)
    print(angle_a, angle_b, center)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        print("I quit!")
        break

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()