Image is too large for uploading, size is 2160*2880.
here is the code:
cv.imshow only show partial content of this image. but if I save image with cv.imwrite and open the saved image with an application. image have all the content.
Is this a bug or cv2 or I miss something?
import cv2
cv2.namedWindow('image', cv2.WINDOW_AUTOSIZE)
img = cv2.imread("0.png")
cv2.imshow("image", img)
cv2.waitKey(0)
cv2.imwrite("xxx.png", img)
cv2.WINDOW_AUTOSIZE fix the window dimentions , so the image will fill the screen if too big
Try cv2.WINDOW_NORMAL which gives you the ability to change the window size.
after the save you maybe only use imread without namedWindow! (there isn't any other clear explanation)
Suggestion: You can use matplotlib for the show job, it has many parameters to use..
Related
When I try to import the image into Tableau as floating, the resolution becomes awful, how do I fix this? I have tried importing different file formats: png, and jpg of the same picture but the result is the same.
Could you try with fixed image option.
or
Use horizontal/vertical container use it as fixed and then put image container in it as floating.
I've loaded an image using CV2.imread, and saved it using cv2.imwrite() and scipy.misc.imsave(). In both these cases output image size is bumped. Why is this?
Both input and output images are of file type .jpg
img = cv2.imread(img_src)
scipy.misc.imsave(img, "scipy_original.jpg")
cv2.imwrite("cv2_original.jpg", img)
Input file size is 309kb
Output file size in cv2 is 690kb
output file size in scipy is 399kb
this is the image if you want reference: https://i.imgur.com/0J8ClQn.jpg
OpenCV has different compression levels for jpg, from 0 to 100. The default is 95.
This question discusses it, and this site has examples.
Saving with parameters like this:
cv2.imwrite("cv2_original.jpg", img, [int(cv2.IMWRITE_JPEG_QUALITY), jpg_quality]) where jpg_quality < 95 will reduce the file size.
We are trying to process input image(attached-portion of image is masked becuase of sensitive data) using open cv 3.4.2-1 and getting output with full black colour. Please check attached output image . Please suggest how we can improve the quality to processed image to remove or corp the white space and get only that ID card portion of the image. Because after this,the image will be processed for OCR. Currently due to bad output image OCR failes completely.
Input image -maskes the portion of image
Output image
I need to create thumbnails of pdf files, and I am using Imagemagick to achieve that.
I have tried Pythonmagick and wand to convert the pdf to an image. However, when I try to resize the converted pdf, the resulting image becomes black.
Is there any option to set -define pdf:use-cropbox=true using python wrappers?
Is there any other method in Python to convert a pdf to a thumbnail?
The code is as follows:
import wand
img = wand.image.Image(filename="d:\\test.pdf[0]")
img.resize(160,160)
img.save(filename="d:\\test.jpg")
I found work around for this problem.
Convert pdf into image 1st and save the image. open newly saved image and and resize it.
import wand
img = wand.image.Image(filename="d:\\test.pdf[0]")
img.save(filename="d:\\temp.jpg")
img = wand.image.Image(filename="d:\\temp.jpg")
img.resize(160,160)
img.save(filename="d:\\resized_image.jpg")
I am still waiting for better answer.
I faced the same problem today. I found another solution in other post.
The reason why the image turns to black is that the background is transparent in PDF file. Since JPG file cannot recognize the alpha-channel (which record the transparent pixel information). JPG files will set those transparent pixel into black as default.
# Use the following two lines to fix this error
# img_page.background_color = Color('white')
# img_page.alpha_channel = 'remove'
with Image(filename="file.pdf",resolution= 350) as img_pdf:
num_pages = len(img_pdf.sequence)
for page, img in enumerate(img_pdf.sequence):
img_page = Image(image=img)
img_page.background_color = Color('white')
img_page.alpha_channel = 'remove'
img_page.resize(900,1200)
img_page.save(filename="file"+str(page)+".jpg")
if page == 0:
img_page.resize(500, 500)
img_page.save(filename="thumbnail.jpg")
ref: Python Wand convert PDF to PNG disable transparent (alpha_channel)
You can do it without using temporary files - if you don't depend on JPG.
The following works for me:
import wand
img=wand.image.Image(filename="/home/vagrant/tmp/wand/law.pdf[0]")
img.format='png'
img.resize(220,220)
img.save(filename="/home/vagrant/tmp/wand/law_2.png")
I have to create a custom photolib like the default one, with animation etc. I had some doubts..
1. Doubt
Should I create 3 images (Thumbnail image, 320*480 image to display full image and original size image in case user share the image) (I am storing this all in app doc directory)
Or should I only store the original image and crop them wen required in 2 other images? In this case, if I use scroll view to display cropped images, how do I know what the user is seeing? And when do I crop next images to keep them ready to display?
(Can anything like reusable cells be created here like in tableview? If yes, can you give me some idea?)
Also, I am fetching images from doc directory. In this case should I load all images in Array or load in batches?
2. Problem Major:
Also need to compress original image and keep it of same size (I used uijpegrepresentation with compression ratio but with some jpegs after compression. It increases sizes even double the size).
You can use single image and for thumbnail you can Resize at run time else it increase size and performance issue. there is lots of open source library are there which do same what you needed. Please have a look below.
https://github.com/arturgrigor/AGImagePickerController
https://github.com/gdavis/FGallery-iPhone