- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我使用了 opencv 的 minAreaRect对 mnist 数字进行校正。它适用于大多数数字,但在某些情况下,未正确检测到 minAreaRect,这会导致数字进一步倾斜。
此代码适用的图像:
输入图像:
minAreaRect 图片:
校正图像:
但是,为此效果不佳:
输入图像: minAreaRect 图片: 校正图像:
我想在这里提到我确实使用过:#coords = np.column_stack(np.where(thresh>0)) 但是,这根本不起作用。请建议使用 opencv 的 minAreaRect(Preferred) 函数的解决方案。我已经用几张图片进行了测试,我明白问题出在最小面积矩形的形成,在第二个例子中,很明显最小面积矩形是不可见的(因为它通过数字本身)。
代码如下:
import numpy as np
import cv2
image=cv2.imread('MNIST/mnist_png/testing/9/73.png')#for 4##5032,6780 #8527,2436,1391
gray=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)## for 9 problem with 4665,8998,73,7
gray=cv2.bitwise_not(gray)
Gblur=cv2.blur(gray,(5,5))
thresh=cv2.threshold(Gblur,0,255,cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
#cv2.imshow("gray_thresh_blur",thresh)
#Finding Contours will be used to draw the min area rectangle
_,contours,_=cv2.findContours(thresh.copy(),cv2.RETR_LIST,cv2.CHAIN_APPROX_NONE)
cnt1 = contours[0]
cnt=cv2.convexHull(contours[0])
angle = cv2.minAreaRect(cnt)[-1]
print("Actual angle is:"+str(angle))
rect = cv2.minAreaRect(cnt)
p=np.array(rect[1])
#print(p[0])
if p[0] < p[1]:
print("Angle along the longer side:"+str(rect[-1] + 180))
act_angle=rect[-1]+180
else:
print("Angle along the longer side:"+str(rect[-1] + 90))
act_angle=rect[-1]+90
#act_angle gives the angle with bounding box
if act_angle < 90:
angle = (90 + angle)
print("angleless than -45")
# otherwise, just take the inverse of the angle to make
# it positive
else:
angle=act_angle-180
print("grter than 90")
# rotate the image to deskew it
(h, w) = image.shape[:2]
center = (w // 2, h // 2)
M = cv2.getRotationMatrix2D(center, angle, 1.0)
rotated = cv2.warpAffine(image,M,(w,h),flags=cv2.INTER_CUBIC,borderMode=cv2.BORDER_REPLICATE)
box = cv2.boxPoints(rect)
print(box)
box = np.int0(box)
print(box)
p=cv2.drawContours(thresh,[box],0,(0,0,255),1)
print("contours"+str(p))
cv2.imwrite("post/MinAreaRect9.png",p)
cv2.imwrite("post/Input_9.png", image)
cv2.imwrite('post/Deskewed_9.png', rotated)
最佳答案
需要注意的几点:
gray=cv2.bitwise_not(gray)
cv2.RETR_EXTERNAL
。contours=cv2.findContours(thresh.copy(),cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)[1]
有了这些变化:
关于python - 使用 opencv 的 minAreaRect() 去偏斜 MNIST 数据集图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51237834/
我的机器学习算法已经学习了 MNIST 数据库中的 70000 张图像。我想在 MNIST 数据集中未包含的图像上对其进行测试。但是,我的预测函数无法读取我的测试图像的数组表示。 如何在外部图像上测试
我正在尝试创建我自己的 MNIST 数据版本。我已将训练和测试数据转换为以下文件; test-images-idx3-ubyte.gz test-labels-idx1-ubyte.gz train-
我通过 pip 在我的 Windows 设备上安装了 python-mnist 包,正如 Github 文档中所述,方法是在我的 Anaconda 终端中输入以下命令: pip install pyt
描述 Fashion Mnist 是一个类似于 Mnist 的图像数据集. 涵盖 10 种类别的 7 万 (6 万训练集 + 1 万测试集) 个不同商品的图片. Tensor
该模型现在只能使用 tf. 识别单个字母。我怎样才能让它识别连续的字母单词? 最佳答案 手写数字识别。 ... MNIST 是一个广泛用于手写数字分类任务的数据集。它由 70,000 个标记为 28x
我已经从 MNIST 训练集中解压了第一张图像,并且可以访问 (28,28) 矩阵。 [[ 0 0 0 0 0 0 0 0 0 0 0 0 0 0
这是我学习的一部分。我知道标准化确实有助于提高准确性,因此将 mnist 值除以 255。这会将所有像素除以 255,因此 28*28 的所有像素的值将在 0.0 到 1.0 范围内. 现在我厌倦了将
我已成功将 MNIST 数据下载到扩展名为 .npy 的文件中。当我打印第一张图像的几列时。我得到以下结果。这里每个数字代表什么? a= np.load("training_set.npy") pri
我用tensorflow写了一个程序来处理Kaggle的数字识别问题。程序可以正常运行,但训练准确率总是很低,大约10%,如下: step 0, training accuracy 0.11 step
在 cnn_mnist.py例如,脚本首先加载训练和测试数据,如您从 120 行到 124 行中看到的那样。当我打印 print(train_data.shape) 时,我得到 (55000, 784
我研究神经网络有一段时间了,用python和numpy做了一个实现。我用 XOR 做了一个非常简单的例子,它运行良好。所以我想我更进一步尝试 MNIST 数据库。 这是我的问题。我正在使用具有 784
我目前正在研究手写数字识别问题。 首先,我针对 MNIST 数据集测试了示例手写数字。 我的准确率为 53%,我需要 90% 以上的准确率。 以下是我迄今为止为提高准确性所做的尝试。 创建了我自己的数
我正在尝试使用我自己的数字图像数据集测试 mnist。 我为此写了一个 python 脚本,但它给出了一个错误。错误在代码的第 16 行。实际上我无法发送图像进行测试。给我一些建议。提前致谢。 imp
我知道这可能是一个愚蠢的问题,但我真的不明白为什么。下面是我尝试从训练数据中打印单个图像和具有相同索引的标签的代码 import matplotlib.pyplot as plt from tenso
我尝试使用以下数据集在 python 中制作一个能够识别手写数字的脚本:http://deeplearning.net/data/mnist/mnist.pkl.gz . 关于这个问题和我试图实现的算
我正在尝试解决 Android 设备上的 MNIST 分类问题。我已经有一个经过训练的模型,现在我希望能够识别照片上的单个数字。 拍完照片后,我会进行一些预处理,然后再将图像传递给模型。这是原始图像的
MNIST 数据集介绍 MNIST 包含 0~9 的手写数字, 共有 60000 个训练集和 10000 个测试集. 数据的格式为单通道 28*28 的灰度图. LeNet 模型
我想导入 mnist digits 数字以在一个图中显示,并编写这样的代码, import keras from keras.datasets import mnist import matplotl
我目前正在研究数字手写识别问题。我发现很多state-of-art算法对mnist dateset采用了一些预处理方法,比如deskewing和jittering(我不知道'jittering'是什么
我到处找,但找不到我想要的。基本上,MNIST 数据集具有像素值在范围 [0, 255] 内的图像。 .人们说,一般来说,最好做到以下几点: 将数据缩放到 [0,1]范围。 将数据标准化为具有零均值和
我是一名优秀的程序员,十分优秀!