示例#1
0
def detectresol(img):
    typ, val = passzbar.passzbar(img)
    if typ:
        x, y = val.decode('ascii').strip().split(',')
        xlst = x.split(':')
        ylst = y.split(':')
        return [list(map(int, xlst)), list(map(int, ylst))]
    else:
        #raise RuntimeError("QR Code cannot be detected")
        return None
示例#2
0
def detectresol(img):
    typ, val = passzbar.passzbar(img)
    if typ:
        x, y = val.decode('ascii').strip().split(',')
        xlst = x.split(':')
        ylst = y.split(':')
        return [list(map(int, xlst)), list(map(int, ylst))]
    else:
        #raise RuntimeError("QR Code cannot be detected")
        return None
示例#3
0
def getcroppedarea(img, markersize):
    #use template matching to detect area to be cropped
    grayimg = getgrayimage(img)
    # detect top-left marker using template matching
    marker_tl = cv2.resize(MARKER_TL, (markersize, markersize))
    matched = cv2.matchTemplate(grayimg, marker_tl,
                                cv2.TM_CCORR_NORMED)  #returns float32
    (minval, maxval, minloc, maxloc) = cv2.minMaxLoc(matched)

    mkrect = getmarkerboundingrect(grayimg, maxloc, markersize)
    pos_tl = (mkrect.x + mkrect.w, mkrect.y + mkrect.h)
    #pos_tl = (maxloc[0]+markersize, maxloc[1]+markersize)

    # detect bottom-right marker using template matching
    marker_br = cv2.resize(MARKER_BR, (markersize, markersize))
    matched = cv2.matchTemplate(grayimg, marker_br,
                                cv2.TM_CCORR_NORMED)  #returns float32
    (minval, maxval, minloc, maxloc) = cv2.minMaxLoc(matched)

    mkrect = getmarkerboundingrect(grayimg, maxloc, markersize)
    pos_br = (mkrect.x, mkrect.y)
    #pos_br = maxloc

    #detect QR code
    qrarea = img[pos_br[1]:, :img.shape[0] - pos_br[1]]
    typ, val = passzbar.passzbar(qrarea)

    if not typ:
        return None, None
    strval = val.decode('ascii').strip()
    #print(strval)

    #cv2.circle(img, pos_tl, 5, (255, 0, 0), -1)
    #cv2.circle(img, pos_br, 5, (0, 255, 0), -1)
    #print(pos_tl, pos_br
    #cv2.imshow("hoge", img)
    #cv2.imshow("hoge", img[pos_tl[1]:pos_br[1], pos_tl[0]:pos_br[0]])
    # crop and return detected area
    return strval, img[pos_tl[1]:pos_br[1], pos_tl[0]:pos_br[0]]
示例#4
0
def getcroppedarea(img, markersize):
    #use template matching to detect area to be cropped
    grayimg = getgrayimage(img)
    # detect top-left marker using template matching
    marker_tl = cv2.resize(MARKER_TL, (markersize, markersize))
    matched = cv2.matchTemplate(grayimg, marker_tl, cv2.TM_CCORR_NORMED) #returns float32
    (minval, maxval, minloc, maxloc) = cv2.minMaxLoc(matched)
    
    mkrect = getmarkerboundingrect(grayimg, maxloc, markersize)
    pos_tl = (mkrect.x+mkrect.w, mkrect.y+mkrect.h)
    #pos_tl = (maxloc[0]+markersize, maxloc[1]+markersize)
    
    # detect bottom-right marker using template matching
    marker_br = cv2.resize(MARKER_BR, (markersize, markersize))
    matched = cv2.matchTemplate(grayimg, marker_br, cv2.TM_CCORR_NORMED) #returns float32
    (minval, maxval, minloc, maxloc) = cv2.minMaxLoc(matched)

    mkrect = getmarkerboundingrect(grayimg, maxloc, markersize)
    pos_br = (mkrect.x, mkrect.y)
    #pos_br = maxloc

    #detect QR code
    qrarea = img[pos_br[1]:,:img.shape[0]-pos_br[1]]
    typ, val = passzbar.passzbar(qrarea)
    
    if not typ:
        return None, None
    strval = val.decode('ascii').strip()
    #print(strval)
    
    #cv2.circle(img, pos_tl, 5, (255, 0, 0), -1)
    #cv2.circle(img, pos_br, 5, (0, 255, 0), -1)
    #print(pos_tl, pos_br
    #cv2.imshow("hoge", img)
    #cv2.imshow("hoge", img[pos_tl[1]:pos_br[1], pos_tl[0]:pos_br[0]])
    # crop and return detected area
    return strval, img[pos_tl[1]:pos_br[1], pos_tl[0]:pos_br[0]]