Skip to content

error: OpenCV(4.0.0) /io/opencv/modules/dnn/src/caffe/caffe_io.cpp:1132: error: (-2:Unspecified error) FAILED: fs.is_open(). Can't open "frozen_east_text_detection.pb" in function 'ReadProtoFromBinaryFile' #176

@javierfs

Description

@javierfs

Expected behaviour

I have installed opencv-python OpenCV(4.0.0) but seems it cannot find 'frozen_east_text_detection.pb' when running cv2.dnn.readNet

error: OpenCV(4.0.0) /io/opencv/modules/dnn/src/caffe/caffe_io.cpp:1132

Actual behaviour

---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-15-9b59c98d5831> in <module>()
      4 
      5 CTextDetector = ClassTextDetector()
----> 6 boxes = CTextDetector.getTextRegions_EAST(inputImg_1, W, H)

~/disk_user/OCR_project/Classes/ClassTextDetector.py in getTextRegions_EAST(self, inMat, outW, outH)
     20     def getTextRegions_EAST(self, inMat, outW, outH):
     21         layerNames = ["feature_fusion/Conv_7/Sigmoid", "feature_fusion/concat_3"]
---> 22         net = cv2.dnn.readNet('frozen_east_text_detection.pb')
     23 
     24         blob = cv2.dnn.blobFromImage(inMat, 1.0, (outW, outH),(123.68, 116.78, 103.94), swapRB=True, crop=False)

error: OpenCV(4.0.0) /io/opencv/modules/dnn/src/caffe/caffe_io.cpp:1132: error: (-2:Unspecified error) FAILED: fs.is_open(). Can't open "frozen_east_text_detection.pb" in function 'ReadProtoFromBinaryFile'

Steps to reproduce

  • example code
inputImg_1 = thresh.copy()
W = int(inputImg_1.shape[1]/32) * int(32)
H = int(inputImg_1.shape[0]/32) * int(32)
    
CTextDetector = ClassTextDetector()
boxes = CTextDetector.getTextRegions_EAST(inputImg_1, W, H)
def getTextRegions_EAST(self, inMat, outW, outH):
        layerNames = ["feature_fusion/Conv_7/Sigmoid", "feature_fusion/concat_3"]
        net = cv2.dnn.readNet('frozen_east_text_detection.pb')

        blob = cv2.dnn.blobFromImage(inMat, 1.0, (outW, outH),(123.68, 116.78, 103.94), swapRB=True, crop=False)
        start = time.time()
        net.setInput(blob)
        (scores, geometry) = net.forward(layerNames)
        end = time.time()
        # show timing information on text prediction
        print("[INFO] text detection took {:.6f} seconds".format(end - start))

        #print(scores.shape)
        #print(scores)
        (numRows, numCols) = scores.shape[2:4]
        rects = []
        confidences = []

        # loop over the number of rows
        for y in range(0, numRows):
            # extract the scores (probabilities), followed by the geometrical
            # data used to derive potential bounding box coordinates that
            # surround text
            scoresData = scores[0, 0, y]
            xData0 = geometry[0, 0, y]
            xData1 = geometry[0, 1, y]
            xData2 = geometry[0, 2, y]
            xData3 = geometry[0, 3, y]
            anglesData = geometry[0, 4, y]

            # loop over the number of columns
            for x in range(0, numCols):
                # if our score does not have sufficient probability, ignore it
                if scoresData[x] < 0.5:
                    continue

                # compute the offset factor as our resulting feature maps will
                # be 4x smaller than the input image
                (offsetX, offsetY) = (x * 4.0, y * 4.0)

                # extract the rotation angle for the prediction and then
                # compute the sin and cosine
                angle = anglesData[x]
                cos = np.cos(angle)
                sin = np.sin(angle)

                # use the geometry volume to derive the width and height of
                # the bounding box
                h = xData0[x] + xData2[x]
                w = xData1[x] + xData3[x]

                # compute both the starting and ending (x, y)-coordinates for
                # the text prediction bounding box
                endX = int(offsetX + (cos * xData1[x]) + (sin * xData2[x]))
                endY = int(offsetY - (sin * xData1[x]) + (cos * xData2[x]))
                startX = int(endX - w)
                startY = int(endY - h)

                # add the bounding box coordinates and probability score to
                # our respective lists
                rects.append((startX, startY, endX, endY))
                confidences.append(scoresData[x])

        # apply non-maxima suppression to suppress weak, overlapping bounding
        # boxes
        boxes = non_max_suppression(np.array(rects), probs=confidences)

        return boxes
  • operating system
    Ubuntu 18.04.1 LTS
  • architecture (e.g. x86)
  • opencv-python version
    4.00

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions