I am new to the opencv library
I was trying to apply the tutorial for camera calibration however I receive the error that 'gray' is not defined when I use the function cv.cameraCalibrate.
I am afraid that the images are not being read ? Even when I tried to load some checkerboard photos from a directory , still the same problem
you can find the link for the tutorial here
https://docs.opencv.org/3.4/dc/dbb/tutorial_py_calibration.html
The images are not able to load. As a result, for loop is not iterating over the array of images and hence the gray variable inside the loop is never been initialized. So it is showing undefined for gray variable.
Check if your images array is empty then cross-check the path from where you are loading the images.
This is an error you get when the images are not imported correctly.
Check whether the images you are trying to import are in the same folder as your python script.
If they are not and you don't want to move them, you can specify the path to the directory you want the script to look for.
Related
I am trying to resize Nii files so that my program takes less computational resources, I want to rescale them from (240,240,155) to (120,120,155). I have tried using nilearn.image.resample_img module to do so however as it is seen the image below the output is not what I would expect. Need some help to figure this out.
I was playing around with the OpenCV library, and tried to open a small image, with the following code:
import cv2
img = cv2.imread(r'penguin.jpeg')
print(img)
To basically take a look at the array of pixels in the image, however the print simply returns None.
Both my .py file and the image are in my desktop, so I believe the problem is not the path.
I am also aware of some issues with imread() and JPEG images, however I get the same result with the PNG version of this image.
This had been working fine up until today, so I am kinda clueless.
Can anyone tell me what might be happening or what I might be doing less correctly?
Thank you so much in advance!
Consulting the OpenCV-Python Tutorials we are warned that
Even if the image path is wrong, it won’t throw any error, but print img will give you None
where print img is the Python 2 analog of your print(img).
The code you have written is correct and having replicated your problem, I print an array representation of a test penguin.jpeg image locally.
As commented by Rashid Ladjouzi, the path is probably incorrect especially given that you mention the script worked previously. I would test this with the following code which should return True:
import os
print(r'penguin.jpeg' in os.listdir("."))
I have four images, each slices of a larger image. If I string them together horizontally, then I get the larger image. To complete this task, I'm using python 2.7 and the OpenCV library, specifically the hconcat() function. Here is the code:
with open("tempfds.jpg", 'ab+') as f:
f.write(cv2.hconcat(cv2.hconcat(cv2.imread("491411.jpg"),cv2.imread("491412.jpg")),cv2.hconcat(cv2.imread("491413.jpg"),cv2.imread("491414.jpg"))))
When I run it, everything works fine. But when I try to open the image itself, I get an error: Error interpreting JPEG image file (Not a JPEG file: starts with 0x86 0x7e). All the images I'm using are jpg's, so I don't understand why this error is occurring. Any insight is appreciated.
If you want to write a JPEG, you need:
cv2.imwrite('lovely.jpg', image)
where image is all your images concatenated together.
I've got a pretty strange issue. I have several tif images of astronomical objects. I'm trying to use opencv's python bindings to process them. Upon reading the image file, it appears that segments of the images are swapped or rotated. I've stripped it down to the bare minimum, and it still reproduces:
img = cv2.imread('image.tif', 0)
cv2.imwrite('image_unaltered.tif', img)
I've uploaded some samples to imgur, to show the effect. The images aren't super clear, that's the nature of preprocessed astronomical images, but you can see it:
First set:
http://imgur.com/vXzRQvS
http://imgur.com/wig99KR
Second set:
http://imgur.com/pf7tnPz
http://imgur.com/xGn9C77
The same rotated/swapped images appear if I use cv2.imShow(...) as well, so I believe it's something when I read the file. Furthermore, it persists if I save as jpg as well. Opening the original in Photoshop shows the correct image. I'm using opencv 2.4.10, on Linux Mint 17.1. If it matters, the original tifs were created with FITS liberator on windows.
Any idea what's happening here?
I want to find which file is last modified.
I am modifying or updating the 'png' image on each request.
For example: piechart.png is an image; I am modifying this same image to create a new image (having same image name 'piechart.png'). I will be saving & modifying 5 images: (piechart1.png,piechart2.png,... ,piechart5.png).
How can I find which image was modified last ?
Well, this doesn't really answer your question, but it come close.
What you can do, is first download the PIL module, or the Python Imaging Library.
After that, get it installed, and then do the following:
from PIL import Image
Jpeg = Image.open("Yourfile.jpg")
print(Jpeg.info, Jpeg.format, Jpeg.mode, Jpeg.size)
This gives you some of the properties of the photo.
The same thing you can do for PNG images.
For more information about using the PIL module and getting your desired results you can go here:
http://python.developpez.com/cours/pilhandbook/php/image.php
Hope this helps!