OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

My code only works on one image file the rest of the image files are read and saved but untouched by my code I need my code to work on all image files

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

Guest
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,

Code:
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
<p>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.</p>
<p>I tried researching more to find a solution, but I couldn't find one here is my code.</p>
<p>Thanks in advance,</p>
<pre><code>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
</code></pre>
 

Latest posts

ن
Replies
0
Views
1
نعمان منذر محمود الجميلي
ن
S
Replies
0
Views
1
Sikandra
S
Top