Help, How can i print image excel report?
Please, help me?
I use xlsxwriter.
Example of xlsxwriter
This is my code:
product_image = product_product.product_tmpl_id.image
imgdata = base64.b64decode(product_image)
image = Image.open(io.BytesIO(imgdata))
# imgdata = base64.b64decode(product_image)
# image = io.BytesIO(imgdata)
print type(image)
sheet.insert_image(rowx, 12, str(image))
The error is:
warn("Image file '%s' not found." % force_unicode(filename))
How to solve?
My goal is print product image in odoo.
Something like the following should work:
product_image = product_product.product_tmpl_id.image
imgdata = base64.b64decode(product_image)
image = io.BytesIO(imgdata)
worksheet.insert_image('B5', 'myimage.png', {'image_data': image})
See the insert_image() section of the XlsxWriter docs and this example of inserting images from an io.BytesIO byte stream into a worksheet.
Related
I am sending an image by curl to flask server, i am using this curl command
curl -F "file=#image.jpg" http://localhost:8000/home
and I am trying to read the file using OpenCV on the server side.
On the server side I handle the image by this code
#app.route('/home', methods=['POST'])
def home():
data =request.files['file']
img = cv.imread(data)
fact_resp= model.predict(img)
return jsonify(fact_resp)
I am getting this error-
img = cv.imread(data)
TypeError: expected string or Unicode object, FileStorage found
How do I read the file using OpenCV on the server side?
Thanks!
I had similar issues while using opencv with flask server, for that first i saved the image to disk and read that image using saved filepath again using cv.imread()
Here is a sample code:
data =request.files['file']
filename = secure_filename(file.filename) # save file
filepath = os.path.join(app.config['imgdir'], filename);
file.save(filepath)
cv.imread(filepath)
But now i have got even more efficient approach from here by using cv.imdecode() to read image from numpy array as below:
#read image file string data
filestr = request.files['file'].read()
#convert string data to numpy array
file_bytes = numpy.fromstring(filestr, numpy.uint8)
# convert numpy array to image
img = cv.imdecode(file_bytes, cv.IMREAD_UNCHANGED)
After a bit of experimentation, I myself figured out a way to read the file using CV2.
For this I first read the image using PIL.image method
This is my code,
#app.route('/home', methods=['POST'])
def home():
data =request.files['file']
img = Image.open(request.files['file'])
img = np.array(img)
img = cv2.resize(img,(224,224))
img = cv2.cvtColor(np.array(img), cv2.COLOR_BGR2RGB)
fact_resp= model.predict(img)
return jsonify(fact_resp)
I wonder if there is any straight forward way to do this without using PIL.
So incase you want to do something like ,
file = request.files['file']
img = cv.imread(file)
then do it like this
import numpy as np
file = request.files['file']
file_bytes = np.fromfile(file, np.uint8)
file = cv.imdecode(file_bytes, cv.IMREAD_COLOR)
Now you don't need to do cv.imread() again, but can use this in the next line of codes.
This applies to OpenCV v3.x and onwards
Two-line solution, change grayscale to what you need
file_bytes = numpy.fromfile(request.files['image'], numpy.uint8)
# convert numpy array to image
img = cv.imdecode(file_bytes, cv.IMREAD_GRAYSCALE)
I am trying to load an image from oracle database Blob file. To load image i am using the following code
$COM_CODE = 'O003';
$sql = 'select DIGI_SIGN from LC_BLOCK_LIST_TECH_PERS where COM_CODE :COM_CODE';
$s = oci_parse ($c, $sql);
oci_bind_by_name($s, ':COM_CODE', $COM_CODE);
oci_execute($s, OCI_NO_AUTO_COMMIT);
$arr = oci_fetch_assoc($s);
$result = $arr['DIGI_SIGN']->load();
$pdf->Cell(40,5,$result,0,1,'L',0);
Nedd to show the image in a cell. In last cell i am not able to show the image instead binary value shows up.
what am i doing wrong here?
from here, it looks like you need to first create a file, then use standard procedure to write the image to the pdf:
$result = $arr['DIGI_SIGN']->load();
// Here: new question: [php] how to write image file from Oracle BLOB?
// $result goes to a file on server: "/var/appli/img/products/image1.jpg"
$image1 = "/var/appli/img/products/image1.jpg";
$pdf->Cell( 40, 5, $pdf->Image($image1, $pdf->GetX(), $pdf->GetY(), 30), 0, 1, 'L', 0);
Hope it helps.
I am trying to use a CNN code to train 10 images stored in an imageSet. The CNN code rather uses the idx3-ubyte format.
I want to know how to convert from my imageSet data to idx3-ubyte format.
I came across the mnisten command below, but I don't have any Idea how to use it.
Please help.
%Here is my imageSet code that I want to convert to idx3-ubyte format.
%% Load image dataset
imgFolder1 = fullfile('C:\Users\Jay\Desktop\practical-cnn-2015a\NairaNotes');
trainingSet = imageSet(imgFolder1, 'recursive');
%%
for digit = 1:numel(trainingSet)
numImages = trainingSet(digit).Count;
for i = 1:numImages
img = read(trainingSet(digit), i);
im = rgb2gray(im2single(read(trainingSet(digit), i)));
end
end
%% here is the mnisten command I got, but I don't have an idea how to use it
mnisten -d my_image_files_directory_name -o my_prefix -s 32x32
Since I assume you're on Windows, check out this guide.
I am attempting to write a function that stack up series of images into image stack and converting it into a gdf file. I don't really know much about GDF files, so please help me out.
X=[];
for i=1:10
if numel(num2str(i))==1
X{i}=imread(strcat('0000',num2str(i),'.tif'));
elseif numel(num2str(i))==2
X{i}=imread(strcat('000',num2str(i),'.tif'));
end
end
myImage=cat(3,X{1:10});
s=write_gdf('stack.gdf',myImage);
Above is to read my images labeled 00001 to 00010, all in grayscale. Everything is fine except in the last line
s=write_gdf('stack.gdf',myImage);
as when I run it, I receive an error:
Data type uint8 not supported
Any help on what this means? Should I convert it to some other colour format?
Thank you in advance!
I would write the code rather like this (I do not have write_gdf function so I can not properly test the code):
NumberOfFiles = 10;
X={}; % preallocate CELL array
for n=1:NumberOfFiles % do not use "i" as your varable because it is imaginary unit in MatLab
FileName = sprintf('%05d.tif',n);
img = imread(FileName); % load image
X{i} = double(img); % and convert to desired format
end
myImage = cat(3,X{1:NumberOfFiles});
s = write_gdf('stack.gdf',myImage);
Keep in mind that
double(img); % and convert to desired format
will not change data range. Your image even in double format will have data range from 0 to 255 if it was in uint8 format on disk. If you need to normalize your data to 0..1 range you should do
X{i} = double(img)/255;
or in more unversal form
X{i} = double(img) / intmax(class(img));
I'm trying to theme one of my content types, which has images uploaded to each instance using the image attach module.
Using the developer module, I've found the iids value of the uploaded image (eg 305), but i'm having trouble finding out how I can actually display the image in my code. This line outputs the node id of the image which has been uploaded, but how can I then use that?
$image = $node->iids[0];
I've tried using hook_image, but I can't seem to get that working...
Thanks for any help.
This did the trick...
$nodeid = $node->nid;
$get_image = db_query('
SELECT p.filepath as imagefilename
FROM {image_attach} i
LEFT JOIN {image} a ON i.iid = a.nid
LEFT JOIN {files} p ON a.fid = p.fid
WHERE i.nid = %d AND p.filename = "recipe_thumb"', $nodeid);
$obj_image = db_fetch_object($get_image);
$imagefilename = $obj_image->imagefilename;