I’m new to Python. I’m using Glob to Batch Process multiple image files. When I run my code, it processes and saves all image files as it should, but only one image file is affected by my code all other image files are untouched by my code. I need all images to be affected by my code. When I run my code on the two Checker Board image files, only one image file is affected the other image file is untouched by my code as shown in the images.
I tried researching more to find a solution, but I couldn’t find one here is my code.
Thanks in advance,
import numpy as np
import cv2
import os
import glob
from skimage import img_as_ubyte
image_list = []
path = "opencv/imgs/*.*"
for file in glob.glob(path):
print(file)
img = cv2.imread(file)
a = cv2.imread(file)
image_list.append(img)
print(a)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray,50,200,apertureSize=3)
img_blur = cv2.GaussianBlur(gray, (3,5), 2)
edges = cv2.Canny(image=img_blur, threshold1=25, threshold2=50) # Canny Edge Detection
# Apply HoughLinesP method to
# to directly obtain line end points
lines_list =[]
lines = cv2.HoughLinesP(
edges, # Input edge image
1, # Distance resolution in pixels
np.pi/2, # Angle resolution in radians
threshold=225, # Min number of votes for valid line
minLineLength=60, # Min allowed length of line
maxLineGap=400) # Max allowed gap between line for joining them
# Iterate over points
for points in lines:
# Extracted points nested in the list
x0,y1,x0,y2=points[0]
# Draw the lines joing the points
# On the original image
cv2.line(img,(x0,y1),(x0,y2),(0,255,0),4)
# Maintain a simples lookup list for points
lines_list.append([(x0,y1),(x0,y2)])
image_list = np.array(image_list)
# Save the result image
img_number = 1
for image in range(image_list.shape[0]):
input_img = image_list[image,:,:]
lines_image = img_as_ubyte(input_img)
cv2.imwrite(path+str(img_number)+".jpg", lines_image)
img_number +=1
type here
Mark is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.