显然,此图像非常清晰,因为它的清晰度很低并且不是真实的单词。但是,使用此代码,我无法检测到任何东西:
import pytesseract
from PIL import Image, ImageEnhance, ImageFilter
image_name = 'NedNoodleArms.jpg'
im = Image.open(image_name)
im = im.filter(ImageFilter.MedianFilter())
enhancer = ImageEnhance.Contrast(im)
im = enhancer.enhance(2)
im = im.convert('1')
im.save(image_name)
text = pytesseract.image_to_string(Image.open(image_name))
print(text)
Run Code Online (Sandbox Code Playgroud)
输出
, Md?aod?amms
Run Code Online (Sandbox Code Playgroud)
这里有什么想法吗?我的对比功能生成的图像是:
哪个看起来不错?我没有大量的OCR经验。您会在这里建议什么预处理?我尝试过将图像调整为更大的尺寸,这有一点帮助,但还不够,还有一些来自PIL的不同滤镜。没什么特别接近的
python ocr image-recognition python-tesseract image-preprocessing
我正在尝试通过将图像数据集重新缩放为(10,10)来预处理numpy数组中的形状为(28,28)的图像。我为此写了一个函数:
def resize_dataset(images):
resized_images = []
for img in images:
img = img.reshape((28,28))
resized_img = cv2.resize(img, dsize=(10, 10))
resized_images.append(resized_img)
return numpy.array(resized_images)
Run Code Online (Sandbox Code Playgroud)
但是,当我实际尝试重新调整它们的大小时,在出现以下错误cv2.resize:
error: OpenCV(4.0.0) /io/opencv/modules/imgproc/src/resize.cpp:3662: error: (-215:Assertion failed) func != 0 in function 'resize'
Run Code Online (Sandbox Code Playgroud)
在google中,我只发现在用c ++编写东西时犯同样错误的人做的事情非常不同,例如这样:调整图像大小并更改其深度,这是:http : //answers.opencv.org/question/19715/error-215- func-0-in-function-convertto /
那么,如何解决呢?
我有一个不平衡的小数据集,其中包含 4116 张 224x224x3 (RGB) 航拍图像。由于数据集不够大,我很可能会遇到过拟合问题。图像预处理和数据增强有助于解决这个问题,如下所述。
“过度拟合是由于可供学习的样本太少导致您无法训练可以泛化到新数据的模型。如果数据无限,您的模型将暴露于手头数据分布的每个可能方面:您永远不会过拟合。数据增强采用从现有训练样本生成更多训练数据的方法,通过大量随机变换来增强样本,从而产生看起来可信的图像。”
使用 Python 进行深度学习,作者 François Chollet,第 138-139 页,5.2.5 使用数据增强。
我已经阅读了Medium - Image Data Preprocessing for Neural Networks并检查了斯坦福的CS230 - Data Preprocessing和 CS231 - Data Preprocessing课程。它在SO 问题中再次突出显示,我知道没有“一刀切”的解决方案。这是迫使我提出这个问题的原因:
“因为我们想要实现高空间分辨率,所以没有使用翻译增强。”
我知道我将使用Keras - ImageDataGenerator Class,但不知道使用哪些技术和哪些参数来对小对象任务进行语义分割。有人可以启发我吗?提前致谢。:)
from keras.preprocessing.image import ImageDataGenerator
datagen = ImageDataGenerator(
rotation_range=20, # is a value in degrees (0–180)
width_shift_range=0.2, # is a range within which to randomly translate pictures horizontally.
height_shift_range=0.2, # is …Run Code Online (Sandbox Code Playgroud) 我正在尝试为图像分类问题训练 resnet50 模型。在我拥有的图像数据集上训练模型之前,我已经加载了“imagenet”预训练权重。我正在使用 keras 函数 flow_from_directory() 从目录加载图像。
train_datagen = ImageDataGenerator()
train_generator = train_datagen.flow_from_directory(
'./train_qcut_2_classes',
batch_size=batch_size,
shuffle=True,
target_size=input_size[1:],
class_mode='categorical')
test_datagen = ImageDataGenerator()
validation_generator = test_datagen.flow_from_directory(
'./validate_qcut_2_classes',
batch_size=batch_size,
target_size=input_size[1:],
shuffle=True,
class_mode='categorical')
Run Code Online (Sandbox Code Playgroud)
我将生成器作为参数传递给 fit_generator 函数。
hist2=model.fit_generator(train_generator,
samples_per_epoch=102204,
validation_data=validation_generator,
nb_val_samples=25547,
nb_epoch=80, callbacks=callbacks,
verbose=1)
Run Code Online (Sandbox Code Playgroud)
题:
有了这个设置,我如何使用 preprocess_input() 函数在将输入图像传递给模型之前对其进行预处理?
from keras.applications.resnet50 import preprocess_input
Run Code Online (Sandbox Code Playgroud)
我尝试使用 preprocessing_function 参数如下
train_datagen=ImageDataGenerator(preprocessing_function=preprocess_input)
train_generator = train_datagen.flow_from_directory(
'./train_qcut_2_classes',
batch_size=batch_size,
shuffle=True,
target_size=input_size[1:],
class_mode='categorical')
test_datagen = ImageDataGenerator(preprocessing_function=preprocess_input)
validation_generator = test_datagen.flow_from_directory(
'./validate_qcut_2_classes',
batch_size=batch_size,
target_size=input_size[1:],
shuffle=True,
class_mode='categorical')
Run Code Online (Sandbox Code Playgroud)
当我尝试提取预处理输出时,我得到了以下结果。
train_generator.next()[0][0]
array([[[ 91.06099701, 80.06099701, 96.06099701, ..., 86.06099701,
52.06099701, 12.06099701], …Run Code Online (Sandbox Code Playgroud) 为了“方便”,我尝试使用 sklearn.utils.class_weight,compute_class_weight 函数
但是,我收到“类应包含 y 中可能存在的所有有效标签”错误;尽管如此,我 100% 确定我给出了所有的类别标签。
print(np.unique('y_train'), ' classes in training set')
>>> 86 classes in training set
Run Code Online (Sandbox Code Playgroud)
所以这工作没有问题;采取镜头:
print(len(y_train), 'train samples')
>>> 6914 train samples
Run Code Online (Sandbox Code Playgroud)
只是为了确定形状:
y_train.shape
>>> (6914, 1)
Run Code Online (Sandbox Code Playgroud)
所以是的,我有一个训练样本向量;我知道四五个班级完全主导了其余的班级,所以我想增加一些班级的权重。
from sklearn.utils.class_weight import compute_class_weight
class_weights = compute_class_weight('balanced', classes = np.unique(y_train), y = y_train)
>>> ValueError: classes should include all valid labels that can be in y
Run Code Online (Sandbox Code Playgroud)
我在这里。这里有什么问题吗?
这是我得到的一张收据图像,我使用 matplotlib 绘制了它,如果您看到图像,其中的文本不是直的。我该如何去歪斜并修复它?
from skimage import io
import cv2
# x1, y1, x2, y2, x3, y3, x4, y4
bbox_coords = [[20, 68], [336, 68], [336, 100], [20, 100]]
image = io.imread('https://i.ibb.co/3WCsVBc/test.jpg')
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
fig, ax = plt.subplots(figsize=(20, 20))
ax.imshow(gray, cmap='Greys_r')
# for plotting bounding box uncomment the two lines below
#rect = Polygon(bbox_coords, fill=False, linewidth=1, edgecolor='r')
#ax.add_patch(rect)
plt.show()
print(gray.shape)
(847, 486)
Run Code Online (Sandbox Code Playgroud)
我想如果我们想先去歪斜,我们必须找到边缘,所以我尝试使用精明算法找到边缘,然后得到如下所示的轮廓。
from skimage import filters, feature, measure
def edge_detector(image):
image = filters.gaussian(image, 2, mode='reflect')
edges = feature.canny(image) …Run Code Online (Sandbox Code Playgroud) 我目前正在从事一个涉及使用 Tess4j Tesseract OCR 引擎的项目。在从事这个项目时,我遇到了很多网站,这些网站声称 Tesseract 在至少 300 DPI(每英寸点数)的图像上效果最好。
我的问题是为什么在图像中多次提到 DPI。我知道当您扫描一个对象时,您希望以至少 300 DPI 对其进行扫描。我只是不明白为什么这与用相机拍摄的照片有关。据我所知,DPI 是打印机的一个属性。基于此属性,它越高,图像越小,但质量越高。
现在,如果 DPI 与这些图像无关,那么我想知道为什么当我在 72 和 300 之间更改图像的 DPI 属性时,程序的结果会有所不同。是否有我不知道的 Tesseract 预处理?
亲爱的社区,我正在尝试做一些 ocr。
我已经对图像进行了很多预处理(去歪斜,裁剪......)
现在,我可以毫无问题地自己读取数字
但是我无法得到 tesseract 给我一个有意义的结果。
单击顶部的链接查看我正在尝试 OCR 的图像
我缺少更多的预处理吗?
或者我称 tesseract 很糟糕?
我根本没有选择,或者尝试:
config = ('--psm 13 -c tessedit_char_whitelist=0123456789')
Run Code Online (Sandbox Code Playgroud)
编辑 :
有趣的是,我尝试了多种方法:
所以这对我来说非常重要。我可能更喜欢使用 Tesseract,以免花大钱。当我的项目更先进时,我会知道我能做什么。
但我很想听听您对图像预处理的建议!!:-)
所以如果你有建议。
问候 !
我想在不同的照明条件下自动调整手机拍摄的彩色图像的亮度和对比度。请帮助我,我是 OpenCV 新手。
来源: 输入图像
结果: 结果
我所寻求的更多的是本地化的转变。本质上,我希望阴影尽可能亮,如果可能的话,完全消失,并使图像的较暗像素变得更暗,对比度更高,而亮像素变得更白,但不要达到曝光过度或任何其他情况的程度像那样。
我已经尝试过CLAHE,,,,等等Histogram Equalization,但没有任何效果。Binary ThresholdingAdaptive Thresholding
我最初的想法是,我需要中Highlights和并使较暗的像素更接近平均值,同时保持文本和线条尽可能暗。然后也许可以做一个对比滤镜。但我无法得到结果请帮助我。
谁能帮助我使用opencv Python将RGB色彩空间图像转换为YUV色彩空间图像和YCbCr色彩空间图像?
python opencv image-processing image-preprocessing opencv-python
我正在从事一个天文图像分类项目,目前正在使用 keras 构建 CNN。
我正在尝试构建一个预处理管道,以使用 keras/tensorflow 层来增强我的数据集。为了简单起见,我想实现二面体组的随机变换(即,对于方形图像,90 度旋转和翻转),但似乎tf.keras.preprocessing.image.random_rotation只允许在遵循均匀分布的连续选择范围。
我想知道是否有一种方法可以从指定度数列表中进行选择,在我的例子中是 [0, 90, 180, 270]。
keras tensorflow keras-layer image-preprocessing image-augmentation
python ×9
ocr ×4
keras ×3
opencv ×3
tesseract ×2
brightness ×1
contrast ×1
cv2 ×1
dpi ×1
generator ×1
keras-layer ×1
resnet ×1
scikit-image ×1
tensorflow ×1
tess4j ×1