我正在尝试在pycharm中使用EAST文本检测器,但该行出现错误。
(scores, geometry) = net.forward(layerNames)
cv2.error: OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\dnn\src\layers\concat_layer.cpp:95: error: (-201:Incorrect size of input array) Inconsistent shape for ConcatLayer in function 'cv::dnn::ConcatLayerImpl::getMemoryShapes'
代码:
print("[INFO] loading EAST text detector...")
name = 'Pictures/non crop/maths soln analysis 4_89.jpg'
image = cv2.imread(name, 1)
(H, W) = image.shape[:2]
设置新的宽度和高度,然后确定变化的比例 宽度和高度
(newW, newH) = (375, 500)
rW = W / float(newW)
rH = H / float(newH)
# resize the image and grab the new image dimensions
image = cv2.resize(image, (newW, newH))
orig = image.copy()
(H, W) = image.shape[:2]
net = cv2.dnn.readNet("frozen_east_text_detection.pb")
layerNames = [
"feature_fusion/Conv_7/Sigmoid",
"feature_fusion/concat_3"]
根据图像构造斑点,然后执行正向传递 获取两个输出层集的模型
blob = cv2.dnn.blobFromImage(image, 1.0, (W, H),
(123.68, 116.78, 103.94), swapRB=True, crop=False)
start = time.time()
net.setInput(blob)
(scores, geometry) = net.forward(layerNames)
答案 0 :(得分:2)
您不是resizing to a multiple of 32。
重要:EAST文本要求您输入的图像尺寸是32的倍数,因此,如果您选择调整--width和--height值,请确保它们是32的倍数!
答案 1 :(得分:0)
更改此行
private const int ScrollMinLimit = 0;
private const int ScrollMaxLimit = 190;
private void ScrollView_Scrolled(object sender, ScrolledEventArgs e)
{
var val = MathHelper.ReMap(e.ScrollY, ScrollMinLimit, ScrollMaxLimit, 1, 0);
this.infoPanel.Scale = val;
this.infoPanel.Opacity = val;
}
到
public static class MathHelper
{
public static double ReMap(double oldValue, double oldMin, double oldMax, double newMin, double newMax)
{
return (((oldValue - oldMin) / (oldMax - oldMin)) * (newMax - newMin)) + newMin;
}
}
答案 2 :(得分:0)
我在OpenCV 4.1.1中遇到了相同的错误。我正在尝试运行此。我的图片是320x320。
# define the two output layer names for the EAST detector model that
# we are interested -- the first is the output probabilities and the
# second can be used to derive the bounding box coordinates of text
layerNames = [
"feature_fusion/Conv_7/Sigmoid",
"feature_fusion/concat_3"]
# load the pre-trained EAST text detector
print("[INFO] loading EAST text detector...")
net = cv.dnn.readNet(east_network)
# construct a blob from the image and then perform a forward pass of
# the model to obtain the two output layer sets
blob = cv.dnn.blobFromImage(image, 1.0, (W, H),
(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))
但是当我运行它时,出现以下错误:
[INFO] loading EAST text detector...
---------------------------------------------------------------------------
error Traceback (most recent call last)
<ipython-input-11-cb4226399d04> in <module>
15 start = time.time()
16 net.setInput(blob)
---> 17 (scores, geometry) = net.forward(layerNames)
18 end = time.time()
19
error: OpenCV(4.1.1) /io/opencv/modules/dnn/src/layers/concat_layer.cpp:95: error: (-201:Incorrect size of input array) Inconsistent shape for ConcatLayer in function 'getMemoryShapes'
答案 3 :(得分:0)
在终端中简单运行以下命令:
python text_detection.py --image images/car_wash.png --east frozen_east_text_detection.pb
答案 4 :(得分:0)
当大小相同时,不会发生此错误;但是当大小更改为例如从320x320更改为640x640时,确实会发生。 此问题与调整为32的倍数无关。
640x640是32的两倍,但是错误仍然出现。
320x320: OK
,然后640x640: Inconsistent shape for ConcatLayer