分类目录归档:Python

解决Ubuntu16.04 Python3.5 安装 imgaug,matplotlib,scikit-image包失败的问题 | Solve the problem that imgaug, matplotlib, scikit-image packages cannot be installed with Ubuntu16.04 Python3.5

今天尝试在机器上安装imgaug包来进行数据增强,但是发现因为依赖版本问题无法安装,解决方法如下(Ubuntu 16.04, Python 3.5)

首先,确认自己已经编译安装了Opencv3.5或以上版本,然后运行下面的命令即可

pip3 install matplotlib==2.2.5
pip3 install numpy scipy Pillow imageio PyWavelets
pip3 install --no-dependencies scikit-image==0.15.0
pip3 install six
pip3 install --no-dependencies imgaug

现在,你可以尝试在Python中使用imgaug了


Today, I tried to install the imgaug package on my computer for data augmentation, but this pakcage cannot be installed because of dependencies. The solution is as follows (Ubuntu 16.04, Python 3.5)

First, make sure you have compiled and installed Opencv3.5 or above, and then run the following command.

pip3 install matplotlib==2.2.5
pip3 install numpy scipy Pillow imageio PyWavelets
pip3 install --no-dependencies scikit-image==0.15.0
pip3 install six
pip3 install --no-dependencies imgaug

Now you can try to import imgaug package in Python

python在ROS中订阅地图消息,在opencv中可视化

在本例中,博主将介绍如何把OccupancyGrid的地图数据在opencv中可视化。

首先,我们阅读OccupancyGrid的文档,可以发现这个结构体主要分为两部分,其MapMetaData存储的是地图的元数据,比如宽度,高度,分辨率等信息。而int8[] data 是一个行主序的数组,数组的值为当前区域被占用的可能性,值域为[0,100],特别地,未知区域的值为-1。

下面是关键部分的示例代码,我们首先订阅一次/map 的消息,并且获取地图元信息,然后我们创建一个numpy数组,并且将可能性的值转换为0-255的颜色。不过在下面的代码中,我将忽略这一特性。所以在probability > 0 这直接写了color=0 ,实际上你可以使用color = (1 – probability) * 255 来代替这一行。最后,因为map_server生成的默认地图未知区域的颜色为205,所以空的numpy数组在一开始用了205来进行填充。

from nav_msgs.msg import OccupancyGrid
map_message = rospy.wait_for_message("/map", OccupancyGrid, 3)  # type: OccupancyGrid
map_width = map_message.info.width
map_height = map_message.info.height
resolution = map_message.info.resolution
origin = map_message.info.origin.position
map_data = np.reshape(map_message.data, (map_width, map_height))
map_rgb = np.zeros((map_width, map_height, 3), np.uint8)
map_rgb.fill(205)
for row in range(map_height):
    for col in range(map_width):
        probability = map_data[row, col]
        if probability == -1:
            continue
        if probability > 0:
            color = 0
        else:
            color = 255
        map_rgb[row, col] = (color, color, color)
map_rgb = cv2.flip(map_rgb, 0)

 

Python在linux中输出带颜色的文字

参数说明如下

前景色            背景色             颜色
------------------------------------------
 30                40               黑色
 31                41               红色
 32                42               绿色
 33                43               黃色
 34                44               蓝色
 35                45               紫红色
 36                46               青蓝色
 37                47               白色
显示方式           意义
------------------------------
 0                终端默认设置
 1                高亮显示
 4                使用下划线
 5                闪烁
 7                反白显示
 8                不可见

例子

  1. 这将输出蓝色底,黄色字,带下划线的闪烁文字
    print "\033[1;5;33;44;4mHello, world\033[0m"
  2. 这将输出绿色的Login successful
    print "\033[1;32m%s\033[0m" % "Login successful"
  3. 这将输出红色的Wrong password
    print "\033[1;31m%s\033[0m" % "Wrong password"