import tensorflow as tf
`import os`
`import numpy as np`
`import os, glob, cv2`
import os.path
import sys, argparse
dir_path= os.path.dirname(os.path.realpath("cat2.jpeg"))
image_path = sys.argv[1]
filename = os.path.join(dir_path, image_path)
image_size = 128
num_channels = 3
images = []
image = cv2.imread(filename)
image = cv2.resize(image, (image_size, image_size), cv2.INTER_LINEAR)
...
error Traceback (most recent call last)
<ipython-input-41-c0a159fd3a64> in <module>()
1 # resizing the image
----> 2 image = cv2.resize(image, (image_size, image_size), cv2.INTER_LINEAR)
3 images.append(image)
4 images = np.array(images, dtype= np.uint8)
5 images = images.astype('float32')
error: /home/travis/miniconda/conda-bld/conda_1485299292920/work/opencv-3.2.0/modules/imgproc/src/imgwarp.cpp:3492: error: (-215) ssize.width > 0 && ssize.height > 0 in function resize
I've looked at other similar posts and tried to debug this error. Can anyone point out how to get rid of this error by looking at the above code? Is this some internal problem or there is some issue with the code?
Related
import imgaug.augmenters as iaa
import cv2
import glob
from tkinter import Frame
from tkinter import Text
from tkinter import Label
# 1. Load Dataset
images = []
images_path = glob.glob("images/*.jpg")
for img_path in images_path:
img = cv2.imread(img_path)
images.append(img)
# 2. Image Augmentation
augmentation = iaa.Sequential([
# 1. Flip
iaa.Fliplr(0.5),
iaa.Flipud(0.5),
# 2. Affine
iaa.Affine(translate_percent={"x": (-0.2, 0.2), "y": (-0.2, 0.2)},
rotate=(-30, 30),
scale=(0.5, 1.5)),
# 3. Multiply
iaa.Multiply((0.8, 1.2)),
# 4. Linearcontrast
iaa.LinearContrast((0.6, 1.4)),
# Perform methods below only sometimes
iaa.Sometimes(0.5,
# 5. GaussianBlur
iaa.GaussianBlur((0.0, 3.0))
)
])
# 3. Show Images
counter = 0
while True:
augmented_images = augmentation(images=images)
for img in augmented_images:
counter += 1
cv2.imwrite(str(counter) + ".jpg", frame)
cv2.imwrite('Desktop/images/dog.jpg', img) # desired save location
cv2.waitKey(0)
"Traceback (most recent call last):
File "C:/Users/MC/PycharmProjects/pythonProject/Python_Augmentation.py", line 48, in
cv2.imwrite(str(counter) + ".jpg", frame)
NameError: name 'frame' is not defined"
The image augmentation code ran well, but when I tried to save the augmented images this error occurred. I also used capital 'F' instead of 'f' (frame), but I got another error.
"Traceback (most recent call last):
File "C:/Users/MC/PycharmProjects/pythonProject/Python_Augmentation.py", line 49, in
cv2.imwrite(str(counter) + ".jpg", Frame)
cv2.error: OpenCV(4.5.4-dev) :-1: error: (-5:Bad argument) in function 'imwrite'
Overload resolution failed:
img is not a numpy array, neither a scalar
Expected Ptr<cv::UMat> for argument 'img'"
Any type of help is appreciatable. Thanks in advance.
The import was:
from tkinter import Frame
but you using, in line 48: frame (lower 'f').
I am trying to use SVG image files to train a model in Python. When I run the below code in Jupyter notebook, I am getting below error. Also Image.open() does not work here. Is there a way to get this code working for .svg image files?
from PIL import Image
drawing = svg2rlg("/content/America_Online_logo.svg")
base_url = "https://upload.wikimedia.org/wikipedia/commons/0/09/America_Online_logo.svg"
base_image_path = tf.keras.utils.get_file(fname = "America_Online_logo.svg", origin =
base_url,)
Image.open(base_image_path)
a = plt.imread(base_image_path)
from keras.optimizers import gradient_descent_v2
width, height = keras.preprocessing.image.load_img(base_image_path).size
Getting following error:
UnidentifiedImageError Traceback (most recent call last)
`<ipython-input-39-a31080608fad> in <module>()`
from keras.optimizers import gradient_descent_v2
width, height = keras.preprocessing.image.load_img(base_image_path).size
img_nrows = 400
img_ncols = int(width * img_nrows / height)
2 frames
/usr/local/lib/python3.7/dist-packages/PIL/Image.py in open(fp, mode)
warnings.warn(message)
raise UnidentifiedImageError( "cannot identify image file %r" % (filename if filename else
fp))
#!/usr/bin/env python
'''
Usage:
./ssearch.py input_image (f|q)
f=fast, q=quality
Use "l" to display less rects, 'm' to display more rects, "q" to quit.
'''
import sys
import cv2
if __name__ == '__main__':
# If image path and f/q is not passed as command
# line arguments, quit and display help message
if len(sys.argv) < 3:
print(__doc__)
sys.exit(1)
# speed-up using multithreads
cv2.setUseOptimized(True);
cv2.setNumThreads(4);
# read image
im = cv2.imread(sys.argv[1])
# resize image
newHeight = 200
newWidth = int(im.shape[1]*200/im.shape[0])
im = cv2.resize(im, (newWidth, newHeight))
Here i am getting error
AttributeError Traceback (most recent call last)
<ipython-input-7-b88f466ecb3b> in <module>
25 # resize image
26 newHeight = 200
---> 27 newWidth = int(im.shape[1]*200/im.shape[0])
28 im = cv2.resize(im, (newWidth, newHeight))
29
AttributeError: 'NoneType' object has no attribute 'shape'
and explain cv2.imread(sys,argv[1]) line
(2)second question is how do i get nonetype error because i havent
passed my image path from my command line yet
(3) cmd line didnt prompt because program didnt executed with th error
i am sorry i couldnt place entire code
The correct way is:
# read image
im = cv2.imread(sys.argv[1])
if im == None :
sys.exit('Invalid or missing image: ' + sys.argv[1])
BEFORE you try to do anything with your image im.
Have a face_recognition code and trying to change the BGR of some images. Running the code with this line: python3 encode_faces.py --dataset dataset --encodings encodings.pickle. There is a way to bypass the error from below:
OpenCV(3.4.1) Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /tmp/opencv-20180529-55469-97fkx6/opencv-3.4.1/modules/imgproc/src/color.cpp, line 11115
Traceback (most recent call last):
File "encode_faces.py", line 38, in <module>
rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
cv2.error: OpenCV(3.4.1) /tmp/opencv-20180529-55469-97fkx6/opencv-3.4.1/modules/imgproc/src/color.cpp:11115: error: (-215) scn == 3 || scn == 4 in function cvtColor
This is my source code:
# import the necessary packages
#asa s ruleaza
# python3 encode_faces.py --dataset dataset --encodings encodings.pickle
from imutils import paths
import face_recognition
import argparse
import pickle
import cv2
import os
# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--dataset", required=True,
help="path to input directory of faces + images")
ap.add_argument("-e", "--encodings", required=True,
help="path to serialized db of facial encodings")
ap.add_argument("-d", "--detection-method", type=str, default="cnn",
help="face detection model to use: either `hog` or `cnn`")
args = vars(ap.parse_args())
# grab the paths to the input images in our dataset
print("[INFO] quantifying faces...")
imagePaths = list(paths.list_images(args["dataset"]))
# initialize the list of known encodings and known names
knownEncodings = []
knownNames = []
# loop over the image paths
for (i, imagePath) in enumerate(imagePaths):
# extract the person name from the image path
print("[INFO] processing image {}/{}".format(i + 1,
len(imagePaths)))
name = imagePath.split(os.path.sep)[-2]
# load the input image and convert it from RGB (OpenCV ordering)
# to dlib ordering (RGB)
image = cv2.imread(imagePath)
rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
# detect the (x, y)-coordinates of the bounding boxes
# corresponding to each face in the input image
boxes = face_recognition.face_locations(rgb,
model=args["detection_method"])
# compute the facial embedding for the face
encodings = face_recognition.face_encodings(rgb, boxes)
# loop over the encodings
for encoding in encodings:
# add each encoding + name to our set of known names and
# encodings
knownEncodings.append(encoding)
knownNames.append(name)
# dump the facial encodings + names to disk
print("[INFO] serializing encodings...")
data = {"encodings": knownEncodings, "names": knownNames}
f = open(args["encodings"], "wb")
f.write(pickle.dumps(data))
f.close()
Print(image.shape) error=
[INFO] quantifying faces...
[INFO] processing image 1/1401
libpng warning: iCCP: known incorrect sRGB profile
(1080, 1920, 3)
[INFO] processing image 2/1401
Traceback (most recent call last):
File "encode_faces.py", line 38, in <module>
print(image.shape)
AttributeError: 'NoneType' object has no attribute 'shape'
Seems that there was an error with the photos. They had to be recalibrated. DId run another script to save the photos in order to create a new dataset. It worked 2nd time.
On this Image
I am trying to apply:
from PIL import Image
img0 = PIL.Image.open('Entertainment.jpg')
img0 = np.float32(img0)
showarray(img0/255.0)
And I get this error:
TypeErrorTraceback (most recent call last)
<ipython-input-20-c181acf634a8> in <module>()
2 img0 = PIL.Image.open('Entertainment.jpg')
3 img0 = np.float32(img0)
----> 4 showarray(img0/255.0)
<ipython-input-8-b253b18ff9a7> in showarray(a, fmt)
11 f = BytesIO()
12 PIL.Image.fromarray(a).save(f, fmt)
---> 13 display(Image(data=f.getvalue()))
14
15 def visstd(a, s=0.1):
TypeError: 'module' object is not callable
I can't understand why.
What is not callable here?
How can I just display the image?
Image is a module that you imported
from PIL import Image
You can't call it
Image(data=f.getvalue())
There's a show method that may be useful
img0 = PIL.Image.open('Entertainment.jpg')
img0.show()
The problem may stem from how you've imported the display() function. If your import line is:
import IPython.display as display
then you need to invoke display.display() to show the image. For example:
import IPython.display as display
my_image = Image.open('something.jpg')
display.display(my_image)
If you instead invoke the function as
import IPython.display as display
my_image = Image.open('something.jpg')
display(my_image) # INCORRECT
# TypeError: 'module' object is not callable
then you will indeed get the error message in your original post because display is referring to a module, not a function.
Alternatively, if you import the display() function in the following manner, your code will work:
from IPython.display import display
my_image = Image.open('something.jpg')
display(my_image)