I am viewing the image on the screen using open cv in python. But the image which I opened with the code is halfway on the screen. But I want you to look full screen. How can I do that? Could you help?
You can use this:
cv2.namedWindow("WindowName",cv2.WINDOW_FULLSCREEN)
cv2.imshow("WindowName",output_image)
cv2.waitKey(0)
First you have to create a namedWindow with full screen property. Property you should use is cv2.WINDOW_FULLSCREEN from documentation.
You can create a window manually and resize it. For example:
cv2.namedWindow("Image",WINDOW_NORMAL);
cv2.resizeWindow("Image",1366,768); //Enter your size
cv2.imshow("Image",frame);
If the image is not display on a full screen, then resize image using command cv2.resize()! Good luck!
Related
I am trying to make a game in python 3 which requires a background image. I already have the image. The problem here is my image looks small compared to the big screen. I don't want to change the size of the screen because then I would have to redo all the coordinates of the other objects on the screen. Is there any way I can increase the size of the background image?
Ps. I'm using Python 3 and on VS code.
Thanks in advance!
This is the picture of what the small picture looks like.enter image description here
In order to increase the size of the image, you would need too increase the resolution.
Assuming that you are using windows, open the png with Microsoft Photos, and click on the three horizontal dots at the top right.
A dropdown menu will open, press the third option from the top labeled "Resize"
After this, press on "Define custom dimensions" and you may manipulate the dimensions of the image as you like.
Then, simply save the resized image, and use it in your project.
you can also do this using CV2 library
import cv2
image=cv2.imread("image.png")
scale_percent=1.5
width=int(image.shape[1]*scale_percent)
height=int(image.shape[0]*scale_percent)
dimension=(width,height)
resized = cv2.resize(image,dimension, interpolation = cv2.INTER_AREA)
print(resized.shape)
cv2.imwrite("output.png",resized)
OR you can use PIL library as well
from PIL import Image
image = Image.open("image.png")
image.save("output.png", dpi=(image.size[0]*1.5,image.size[1]*1.5))
Hi whenever I use the cv2.imshow function all I get is a black rectangle like this:
My code is here, I am using python:
from cv2 import cv2
image = cv2.imread("scren.png")
cv2.imshow("image2", image)
I have tried using different file types as well as restarting my computer. Does anyone know how to fix this? Thanks.
I'll put the answer from #fmw42 here as it solved for me too and I was looking for it for some hours
Add cv2.waitKey(0) after cv2.imshow(...).
I don't know why it solves, but solved for me.
According to the documentation the imshow function requires a subsequent command to waitKey or else the image will not show. I believe this functionality has to do with how highgui works. So to display an image in Python using opencv you will always have to do something like this:
import cv2
image = cv2.imread(r"path\to\image")
cv2.imshow("image", image)
cv2.waitKey(0)
Note about imshow
This function should be followed by a call to cv::waitKey or cv::pollKey to perform GUI housekeeping tasks that are necessary to actually show the given image and make the window respond to mouse and keyboard events. Otherwise, it won't display the image and the window might lock up. For example, waitKey(0) will display the window infinitely until any keypress (it is suitable for image display). waitKey(25) will display a frame and wait approximately 25 ms for a key press (suitable for displaying a video frame-by-frame). To remove the window, use cv::destroyWindow.
See also.
I take part in a project in which we are making a sudoku solver. I want to print the image of the solved sudoku grid on the screen while our drawing table is drawing the solution on the paper grid.
But I can't find a way to display an image and my code keeps running.
I have looked into - I think - all of the opencv and matplotlib.pyplot functions to display images but every time the code stops when the image is displayed and continues once the image is closed (plt.show() or using cv2.waitKey()).
So if anyone has an idea of a way to display an image while the python code keeps running, I'd be glad to hear it.
Thanks
The PIL/Pillow Image.show() method will leave your image showing on the screen and your code will continue to run.
If you have a black and white image in a Numpy/OpenCV array, you can make it into a PIL Image and display it like this:
from PIL import Image
Image.fromarray(NumpyImg).show()
If your image is colour, you'll need to go from BGR to RGB either using cv2.cvtColor(...BGR2RGB..) or by reversing your 3rd channel something like (untested):
Image.fromarray(NumpyImg[:,:,::-1]).show()
I want to take a screenshot of whole screen in python which is doable(feasible) to me. But if i want to take screenshot of a desired clipped area like the picture shown below means first of all, user should select(clip) a region using mouse pointer and then take screenshot of that area. So i want to say that how to clip a portion of an image in a clipboard?
NOTE: I have found some packages like "clipboard" and "pyperclip" but i couldn't understand how to clip an image? Help me
I got a code but it shows to clip only text. What modifications should be made in it to clip a desired area of an image.
import clipboard
clipboard.copy("abc")
text = clipboard.paste()
print(text)
I would find a python module that allowed you to edit image files, or use a binding to an external program. A tool like pyperclip will enable you to get at the image in python, you will then have to edit the image yourself using a module or something else.
I am creating a program that requires a background image in Python Turtle.
I know how to add the image (bgpic("")) but I need to resize it. I can't use photoshop because I can't then add the file (says that it has no data in the file!).
So how do I resize it through code?
With Pillow you can easily do it :)
here is the doc of the library and the resize function
http://pillow.readthedocs.org/en/3.0.x/reference/Image.html?highlight=resize#PIL.Image.Image.resize