I have generated QR code in openerp using python. It's working successfully. But I Want to display name on qrcode Image. I tried to create in many way, but still i can not get solutions
Python:
a="Client Id: "+vals['client_id']+"\n"+"Client Name: "+vals['name']
qr = QRCode(version=20, error_correction=ERROR_CORRECT_L, box_size=2, border=2)
qr.add_data(a)
qr.make()
im = qr.make_image()
im.save("/home/cryosave_qrcodes/"+vals['client_id']+".png")
Generated QRcode this done by me
But I want show name on qrcode. like following image.
Generated
I tried to create in many way, but still i can not get solutions
Please anyone answer me
This is one way:
We can add text on qrcode, after qr generate.
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
img = Image.open('sample.jpg')
#img = Image.new("RGBA",(100,150),(0,0,0))
draw = ImageDraw.Draw(img)
font = ImageFont.truetype("/home/john/coda/Coda-Heavy.ttf", 20)
# draw.text((x, y),"Sample Text",(r,g,b))
draw.text((10,0),"Sample Text",(100,100,100), font=font)
img.save('/home/john/test.jpg')
Related
Pimoroni has an example that grabs a jpg online and displays it on one of their Inky e-ink displays.
I am wondering if it is possible to do the same thing with an Adafruit MagTag using CircuitPython. In the latest version of CircuitPython, there are BitmapTools that seem like they may be able to convert a .jpg file into a .bmp that is dithered appropriately for an e-ink display. There just doesn't seem to be any example code that shows how to do this.
Is it possible?
Any examples of using bitmaptools.dither(dest_bitmap: displayio.Bitmap, source_bitmapp: displayio.Bitmap, source_colorspace: displayio.Colorspace, algorithm: DitherAlgorithm = DitherAlgorithm.Atkinson)→ None
The code would look a little like this ...
import board
import displayio
import adafruit_imageload
display = board.DISPLAY
bitmap, palette = adafruit_imageload.load("/purple.bmp",
bitmap=displayio.Bitmap,
palette=displayio.Palette)
# Create a TileGrid to hold the bitmap
tile_grid = displayio.TileGrid(bitmap, pixel_shader=palette)
# Create a Group to hold the TileGrid
group = displayio.Group()
# Add the TileGrid to the Group
group.append(tile_grid)
# Add the Group to the Display
display.show(group)
# Loop forever so you can enjoy your image
while True:
pass
... but we would pull in a .jpg and have to do a little work on it so that the greyscale image becomes a dithered .bmp.
Any ideas?
I can pull in a .jpg. I just can't process it and display.
I was also looking for an API or something that might be able to pre-process the image from https://placekitten.com so that it would already be a dithered bitmap file. Does that exist?
I would like to view an image interactively in F# jupyter notebook similarly to how I can do this in python:
from PIL import Image
Image.open("image.png")
and that shows an image.
Is there a straightforward way to do this?
EmguCV, OpenCVSharp and ImageSharp all don't work together with the plotting libraries like Plotly.NET or XPlot to provide this functionality so I can't get something like matplotlib's pyplot.imshow.
In a notebook, you can display an image like this:
#!fsharp
// Load iamge
let data = File.ReadAllBytes("E:\\Downloads\\myImage.png");
// Convert so we can display it as HTML
let b64 = Convert.ToBase64String(data);
HTML($"<img src=\"data:image/png;base64,{b64}\"></img>") // last call without ; gets displayed
// Alt, this one has a semicolon:
// display(HTML($"<img src=\"data:image/png;base64,{b64}\"></img>"));
I needed to view reStructuredText files in JupyterLab, and the best I found so far was #akaihola's answer to a related issue on github.
I added a work around that would allow rendering the file without viewing the source, provided below.
In case anyone else may need it, here's the solution I am working with for now:
import docutils.core
import docutils.writers.html5_polyglot
from IPython.core.magic import register_cell_magic, register_line_magic
from IPython.display import HTML
#register_cell_magic
def rst(line, cell):
"Render ReStructuredText"
writer = docutils.writers.html5_polyglot.Writer()
return HTML(docutils.core.publish_string(cell, writer=writer).decode('UTF-8'))
#register_line_magic
def rstfile(filename):
"Render ReStructuredText"
writer = docutils.writers.html5_polyglot.Writer()
with open(filename, 'r') as file:
cell = file.read()
return HTML(docutils.core.publish_string(cell, writer=writer).decode('UTF-8'))
To view the rst file, without the source:
%rstfile <your-rst-filename>
To use the original solution, as an rst cell, showing both the ReStructuredText source and the rendered output:
%%rst
============
Main title
============
Some **heavy** markup.
I am using jupyter notebook in google collab. My training dataset looks like this:
/data/label1/img1.jpeg
.
.
.
/data/label2/img90.jpeg
I want to import such dataset. Things that I tried
Step1:
!pip install -U -q PyDrive
%matplotlib inline
import matplotlib
import matplotlib.pyplot as plt
from os import walk
import os
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
Step 2:
# 1. Authenticate and create the PyDrive client.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
Step 3
file_to_download = os.path.expanduser('./data/')
file_list = drive.ListFile(
{'q': 'id_of_the_data_directory'})
Not sure how to proceed next. The folder data is my collab notebook folder in the drive. I want to read the images along with labels.In order to do the same I am using the code:
filename_queue=tf.train.string_input_producer(tf.train.match_filenames_once('data/*/*.jpeg'))
image_reader=tf.WholeFileReader()
key,image_file=image_reader.read(filename_queue)
#key is the entire path to the jpeg file and we need only the subfolder as the label
S = tf.string_split([key],'\/')
length = tf.cast(S.dense_shape[1],tf.int32)
label = S.values[length-tf.constant(2,dtype=tf.int32)]
label = tf.string_to_number(label,out_type=tf.int32)
#decode the image
image=tf.image.decode_jpeg(image_file)
#then code to place labels and folders in corresponding arrays
You should upload your dataset in a recursive manner. Here is a sample on how to upload your dataset from your Google Drive to Colab
First of all I want to mention that we cannot access the folder directly. We need to set the mount point and all the drive contents are accessed via that. Thanks to this answer
Follow the steps exactly as given in the answer link given above. But just make sure to change your path according to the new drive folder created.
PS: I still left the question open because you may reach here with image dataset having subfolder names as the labels of the training images, it works for so the solution posted here works for both directories with subfolders as well as directories with files.
I have searched a multiple articles, but unable to get iPython (Python 2.7) to export data to a CSV, and I do not receive an error message to troubleshoot the specific problem, and when I include "print(new_links)" I obtain the desired output; thus, this issue is printing to the csv.
Any suggestions on next steps are much appreciated !
Thanks!
import csv
import requests
import lxml.html as lh
url = 'http://wwwnc.cdc.gov/travel/destinations/list'
page = requests.get(url)
doc = lh.fromstring(page.content)
new_links = []
for link_node in doc.iterdescendants('a'):
try:
new_links.append(link_node.attrib['href'])
except KeyError:
pass
cdc_part1 = open("cdc_part1.csv", 'wb')
wr = csv.writer(cdc_part1, dialect='excel')
wr.writerow(new_links)
Check to make sure the new_links is a list of lists.
If so and wr.writerow(new_links) is still not working, you can try:
for row in new_links:
wr.writerow(row)
I would also check the open statement's file path and mode. Check if you can get it to work with 'w'.