小编Ste*_*zzi的帖子

聚合行 Pandas

我对pandas. 我需要汇总'Names'它们是否具有相同的名称,然后为'Rating''NumsHelpful'(不计算NaN)求平均值。'Review'应该被连接,而'Weight(Pounds)'应该保持不变:

col names: ['Brand', 'Name', 'NumsHelpful', 'Rating', 'Weight(Pounds)', 'Review']

Name             'Brand'                             'Name'
1534             Zing Zang                Zing Zang Bloody Mary Mix, 32 fl oz   
1535             Zing Zang                Zing Zang Bloody Mary Mix, 32 fl oz   
1536             Zing Zang                Zing Zang Bloody Mary Mix, 32 fl oz   
1537             Zing Zang                Zing Zang Bloody Mary Mix, 32 fl oz   
1538             Zing Zang                Zing Zang Bloody Mary Mix, 32 …
Run Code Online (Sandbox Code Playgroud)

python dataframe pandas pandas-groupby

5
推荐指数
1
解决办法
2万
查看次数

google.api_core.exceptions.ServiceUnavailable:503 从插件获取元数据失败,错误:“str”对象没有“before_request”属性

我正在尝试遍历目录中的图像并通过 goodle_api_vision 获取它们的标签。这是我的代码: def run_quickstart(): import io import os import cv2 import numpy as np from google.cloud import vision from google.cloud.vision import types

client = vision.ImageAnnotatorClient(credentials = 'service_acc_key.json')

path = 'E:\wrand\\'
for image_path in os.listdir(path):

    file_name = path + image_path
    content = cv2.imread(file_name)
    # Loads the image into memory
    #with io.open(file_name, 'rb') as image_file:
       # content = image_file.read()
    content = content.tobytes()
    print(type(content))

    image = types.Image(content=content)
    print(type(image))
    response = client.label_detection(image=image)
    labels = response.label_annotations
    print('Labels:')
    for label in labels:
        print(label.description)
        # [END …
Run Code Online (Sandbox Code Playgroud)

python google-vision

4
推荐指数
2
解决办法
3706
查看次数

Numpy 数组转 PIL 图像格式

我正在尝试将图像从 numpy 数组格式转换为 PIL 格式。这是我的代码:

img = numpy.array(image)
row,col,ch= np.array(img).shape
mean = 0
# var = 0.1
# sigma = var**0.5
gauss = np.random.normal(mean,1,(row,col,ch))
gauss = gauss.reshape(row,col,ch)
noisy = img + gauss
im = Image.fromarray(noisy)
Run Code Online (Sandbox Code Playgroud)

此方法的输入是 PIL 图像。此方法应将高斯噪声添加到图像中,并再次将其作为 PIL 图像返回。

任何帮助是极大的赞赏!

python numpy image python-imaging-library

2
推荐指数
1
解决办法
8047
查看次数

COLOR_RGB2GRAY 给出非灰度图像(可能是 jupyter-notebook 的问题)

我正在尝试对图像执行直方图均衡化,但有 2 个问题。首先,我需要为它的灰度版本绘制直方图。当我尝试将 RGB 图像转换为灰度时,输出是蓝色和黄色图像。我的代码如下:

img = cv2.imread(r'D:/UNI/Y3/DIA/2K18/lab.jpg') 
RGB_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
gray = cv2.cvtColor(RGB_img, cv2.COLOR_RGB2GRAY)
plt.imshow(gray)
plt.title('My picture (before hist. eq.)')
plt.show()
Run Code Online (Sandbox Code Playgroud)

这是 Jupyter Notebook 的输出:

这是 Jupyter Notebook 的输出

但我刚刚意识到,如果我保存它是否正确保存:

在此处输入图片说明

由于我需要提交 jupyter 文档,我该如何解决这个问题?谢谢!

其次,我执行直方图均衡,但是当我尝试水平堆叠图像时,我从这段代码中得到以下错误:

equ = cv2.equalizeHist(gray)
res = np.hstack((img,equ))
Run Code Online (Sandbox Code Playgroud)

错误-> all the input arrays must have same number of dimensions

据我所知,我根本没有触及图像的尺寸......


编辑:

在此处输入图片说明

左图应该是RGB

python opencv jupyter-notebook

0
推荐指数
1
解决办法
5161
查看次数