I have Ubuntu 16.04. I have converted image through terminal using the following command:
convert myfigure.png myfigure.jpg
But I want to resize the height and width of the converted image. Is there any way to do this?
You can use the imutils python package.
import imutils
frameData = vs.read()
frameData = imutils.resize(frameData, width=600)
This should help.
Related
I am trying to show a simple image output in pycharm using opencv but the output always contains white boarders around the image and I am not sure how to remove those boarders. I am using linux mint.This is the image I got as output, as I mentioned it has white boarders around the image.
I used the following code
import cv2
img = cv2.imread(path)
cv2.imshow("Output",img)
cv2.waitkey(0)
import cv2;
input_path = 'input.JPG';
output_path = 'output.jpg';
input_image = cv2.imread(input_path,cv2.IMREAD_UNCHANGED)
cv2.imwrite(output_path,input_image)
Check the input output image comparision here
This is the original image - https://imgur.com/a/iRAS9NY
There is a color change between input and output image. Please help me modify the code so the input and output images are exactly matching. Thanks!
The image is in AdobeRGB format. That is the issue. We are using GIMP to convert into SRGB and then using it in our sfotware. It is working fine now.
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..
I am using namedWindow() function in my code to resize the image's window. The mouse cursor showing i can resize the windows, but it actually can't. Here is my code
import numpy as np
import cv2
img=cv2.imread('/home/jeff/Downloads/iphone.png', 1)
cv2.namedWindow('image',cv2.WINDOW_NORMAL)
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Please assist. Thanks.
Replace code line cv2.namedWindow('image',cv2.WINDOW_NORMAL) with following:
cv2.namedWindow('image',cv2.WINDOW_AUTOSIZE)
There is a bug (at least in v3.2.0) that the resizing does not work if the image is bigger than the screen resolution. See the issue on GitHub.
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")