0

The full code is -

def recognize(im):
    orig = im.copy()
    (origH, origW) = im.shape[:2]
    (newW, newH) = (320, 320)
    rW = origW / float(newW)
    rH = origH / float(newH)
    im = cv2.resize(im, (newW, newH))
    (H, W) = im.shape[:2]
    
    # construct a blob from the image and then perform a forward pass of
    # the model to obtain the two output layer sets
    blob = cv2.dnn.blobFromImage(im, 1.0, (W, H),
        (123.68, 116.78, 103.94), swapRB=True, crop=False)
    net.setInput(blob)
    (scores, geometry) = net.forward(layerNames)
    
    (rects, confidences) = decode_predictions(scores, geometry)
    boxes = non_max_suppression(np.array(rects), probs=confidences)

    results = list()
    for (startX, startY, endX, endY) in boxes:
        startX = int(startX * rW)
        startY = int(startY * rH)
        endX = int(endX * rW)
        endY = int(endY * rH)
        cv2.rectangle(orig, (startX, startY), (endX, endY), (0, 255, 0), 2)
        im = orig[startY:endY, startX:endX]
             
        
        #recognizer starts here
        dX = int((endX - startX) * 0.03)
        dY = int((endY - startY) * 0.03)
        
        startX = max(0, startX - dX)
        startY = max(0, startY - dY)
        endX = min(origW, endX + (dX * 2))
        endY = min(origH, endY + (dY * 2))
        im2 = orig[startY:endY, startX:endX]
        
        text = pytesseract.image_to_string(im2,config='--psm 10 --oem 3')
        
        cv2.putText(orig,text,(startX, startY-10),cv2.FONT_HERSHEY_COMPLEX,0.5,(0, 255, 0),1)
        
        
    return orig

How to fix that error? Any help would be appreciated. I was trying all existing solutions but nothing works for me. I have no idea why I still getting this error. Thank you

  • What is the variable `im` supposed to be? Could you add your code where you assign a value to `im`? – D Malan Oct 18 '22 at 20:16

0 Answers0