Esempio n. 1
0
 def as_gif(self, duration=100):
     """
     Helpful to visualize it in a notebook
     """
     self.labeled_frames[0]['frame'].save(
         "/tmp/out.gif",
         save_all=True,
         append_images=[f['frame'] for f in self.labeled_frames[1:]],
         duration=duration,
         loop=0,
     )
     return IPythonImage(filename="/tmp/out.gif")
Esempio n. 2
0
 def show(self):
     return IPythonImage(self._thumbnail)
              bottom,
              font=album_name_font,
              fill=outline_color)

    draw.text((band_x, band_y), top, (255, 255, 255), font=band_name_font)
    draw.text((album_x, album_y),
              bottom, (255, 255, 255),
              font=album_name_font)

    return img


img = display_cover(top='top', bottom='bottom')
img.save('sample-out.png')
## Use the following to read the img file and display the results
IPythonImage(filename='sample-out.png')
## Display an image with the text 'Python' on top and 'Data Science' below
img = display_cover(top='Python', bottom='Data Science')
img.save('sample-out.png')
IPythonImage(filename='sample-out.png')

## LOAD WIKIPEDIA PAGE
import requests

wikipedia_link = 'https://en.wikipedia.org/wiki/Special:Random'

raw_random_wikipedia_page = requests.get(wikipedia_link)
## Grab text file with the page's XML
page = raw_random_wikipedia_page.text
## print(page)
title_begin_index = page.find("<title>") + 7
Esempio n. 4
0
a=page.find('<title>')
b=page.find('</title>')
c=len('<title>')
d=page[a+c:b]
band_title=d.replace(' - Wikipedia','')




wikipedia_link='https://en.wikipedia.org/wiki/Special:Random'
raw_random_wikipedia_page=requests.get(wikipedia_link)
page=raw_random_wikipedia_page.text
print(page)



a=page.find('<title>')
b=page.find('</title>')
c=len('<title>')
d=page[a+c:b]
album_title=d.replace(' - Wikipedia','')
print("Your band: ", band_title)
print("Your album: ", album_title)

img=display_cover(top=band_title,bottom=album_title)
img.save('gaurav2.png')

IPythonImage(filename='gaurav.png')
IPythonImage(filename='gaurav2.png')

Esempio n. 5
0
def display_img(img_path):
    img = IPythonImage(filename=img_path)
    st.image(Image.open(img))
def display_cover(top, bottom):

    import requests
    img = display_cover(top='top', bottom='bottom')
    name = 'album_art_raw.png'
    # Now let's make get an album cover.
    # https://picsum.photos/ is a free service that offers random images.
    # Let's get a random image:
    album_art_raw = requests.get('https://picsum.photos/500/500/?random')
    img.save('album_art_raw.png')
    IPythonImage(filename='album_art_raw.png')
    # and save it as 'album_art_raw.png'
    with open(name, 'wb') as album_art_raw_file:
        album_art_raw_file.write(album_art_raw.content)
    # Now that we have our raw image, let's open it
    # and write our band and album name on it
    img = Image.open("album_art_raw.png")
    draw = ImageDraw.Draw(img)

    # We'll choose a font for our band and album title,
    # run "% ls /usr/share/fonts/truetype/dejavu" in a cell to see what else is available,
    # or download your own .ttf fonts!
    band_name_font = ImageFont.truetype(
        "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf",
        25)  # 25pt font
    album_name_font = ImageFont.truetype(
        "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf",
        20)  # 20pt font

    # the x,y coordinates for where our album name and band name text will start
    # counted from the top left of the picture (in pixels)
    band_x, band_y = 50, 50
    album_x, album_y = 50, 400

    # Our text should be visible on any image. A good way
    # of accomplishing that is to use white text with a
    # black border. We'll use the technique shown here to draw the border:
    # https://mail.python.org/pipermail/image-sig/2009-May/005681.html
    outline_color = "black"

    draw.text((band_x - 1, band_y - 1),
              top,
              font=band_name_font,
              fill=outline_color)
    draw.text((band_x + 1, band_y - 1),
              top,
              font=band_name_font,
              fill=outline_color)
    draw.text((band_x - 1, band_y + 1),
              top,
              font=band_name_font,
              fill=outline_color)
    draw.text((band_x + 1, band_y + 1),
              top,
              font=band_name_font,
              fill=outline_color)

    draw.text((album_x - 1, album_y - 1),
              bottom,
              font=album_name_font,
              fill=outline_color)
    draw.text((album_x + 1, album_y - 1),
              bottom,
              font=album_name_font,
              fill=outline_color)
    draw.text((album_x - 1, album_y + 1),
              bottom,
              font=album_name_font,
              fill=outline_color)
    draw.text((album_x + 1, album_y + 1),
              bottom,
              font=album_name_font,
              fill=outline_color)

    draw.text((band_x, band_y), top, (255, 255, 255), font=band_name_font)
    draw.text((album_x, album_y),
              bottom, (255, 255, 255),
              font=album_name_font)

    return img
Esempio n. 7
0

#创建模型
model = create_model(optimizer='Adam',
                     kernel_initializer='uniform',
                     activation='relu')
model.summary()

#----------------------------------------------------------------
#                         第七步 模型绘制
#----------------------------------------------------------------
from keras.utils.vis_utils import plot_model
from IPython.display import Image as IPythonImage

plot_model(model, to_file="model.png", show_shapes=True)
display(IPythonImage('model.png'))

#----------------------------------------------------------------
#                         第八步 模型训练+输出结果
#----------------------------------------------------------------
from keras.callbacks import ModelCheckpoint
from sklearn.metrics import classification_report
import matplotlib.pyplot as plt


#绘制图形
def plot_loss_accuracy(history):
    # Loss
    plt.figure(figsize=[8, 6])
    plt.plot(history.history['loss'], 'r', linewidth=3.0)
    plt.plot(history.history['val_loss'], 'b', linewidth=3.0)
Esempio n. 8
0
def get_band_album_titles():
    wikipedia_link = 'https://en.wikipedia.org/wiki/Special:Random'

    raw_random_wikipedia_page = requests.get(wikipedia_link)

    tree = fromstring(raw_random_wikipedia_page.content)
    raw_title = tree.findtext('.//title')
    band_title = raw_title.split('-')
    raw_random_wikipedia_page = requests.get(wikipedia_link)

    tree = fromstring(raw_random_wikipedia_page.content)
    raw_title = tree.findtext('.//title')
    album_title = raw_title.split('-')

    return (band_title[0].rstrip() + '-' + album_title[0].rstrip())

# first part use data science and python as bottom and top
img = display_cover(top='Python', bottom='Data Science')
img.save('sample-out.png')

IPythonImage(filename='sample-out.png')

# second part capture two random titles and make them top and bottom text
band_title, album_title = get_band_album_titles().split('-')

album_cover = display_cover(top=band_title, bottom=album_title)
album_cover.save('album-cover.png')

IPythonImage(filename='album-cover.png')
Esempio n. 9
0
"""
Распознавание продуктов
"""
# Для решения данной задачи в работе Viola Jones были использованы
# (cascade object detection with AdaBoost learning algorithm) и
# Histogram of Oriented Gradients (HOG).
# получилась следующая точность
from IPython.display import Image as IPythonImage
IPythonImage('docs/images/packs_detection_accuracy.png', width=600)

# сделав несколько улучшений получились рез-ты
IPythonImage('docs/images/packs_detection_accuracy_improved.png', width=600)

# Следующие задач компьюетрного зрения успешно решаются сейчас
IPythonImage('docs/images/cv_common_tasks.png', width=800)

# Модели https://github.com/tensorflow/models/tree/master/research/deeplab
# успешно решают задачи семантической сегментации
# Модели https://github.com/tensorflow/models/tree/master/research/object_detection
# решают задачи нахождения предметов

# Для распознавания пачек используем модель SSD Mobilenet V1
# натренированную на датасете COCO

import cv2
import pandas as pd
import numpy as np
import os
import io
import tensorflow as tf
import requests as rq


# In[31]:


album_raw = rq.get("https://raw.githubusercontent.com/arneec/digits-recognition/master/5.jpg")   # random images
with open("image.jpg",'wb') as raw_file:   #widthbairer 
    raw_file.write(album_raw.content)


# In[32]:


img = Image.open("image.jpg")
IPythonImage(filename= 'image.jpg')   #To display the image


# In[33]:


img=misc.imread("image.jpg")


# In[34]:


print(features.shape)


# In[35]:
Esempio n. 11
0
    draw.text((album_x + 1, album_y + 1),
              bottom,
              font=album_name_font,
              fill=outline_color)

    draw.text((band_x, band_y), top, (255, 255, 255), font=band_name_font)
    draw.text((album_x, album_y),
              bottom, (255, 255, 255),
              font=album_name_font)

    return img


img = display_cover(top='top', bottom='bottom')
img.save('sample-out.png')
IPythonImage(filename='sample-out.png')

album_cover = display_cover(top="Python", bottom="Data Science")
album_cover.save("album-cover-out.png")

IPythonImage(filename="album-cover-out.png")

# -------------------------------------------------------------------------------------

wikipedia_link = 'https://en.wikipedia.org/wiki/Special:Random'
raw_random_wikipedia_page = requests.get(wikipedia_link)
page = raw_random_wikipedia_page.text
#print(page)

band_title = page[page.find('<title>') + 7:page.find(' - Wikipedia')]
#band_title