我试图写轮廓图像,但我只得到一个图像作为输出。我有3个图像,我想写所有3个图像轮廓输出。你知道吗
我想在文件名下创建一个子文件夹,并将分段图像写入相关文件夹。你知道吗
我想实施操作系统路径拆分但直到现在都没有成功
import sys
import glob,os
import cv2
class Imageprocessing:
def readImages(inputFolder):
ext = ['.png', '.jpg', '.gif', '.jpeg', '.tif', '.tiff'] # Add image formats here
files = []
path = inputFolder + "\\*.*"
#print (path)
files = glob.glob(path)
#[files.extend(glob.glob(inputFolder + '*.' + e)) for e in ext]
#print(files)
imageFiles=[]
for i in files:
exten=os.path.splitext(i)[1]
if exten in ext:
imageFiles.append(i)
return imageFiles
def processImage(imageFiles):
for imagePath in imageFiles:
print(imagePath)
image = cv2.imread(imagePath)
cv2.imshow("1",image)
cv2.waitKey()
ret, thresh = cv2.threshold(image,0,255,cv2.THRESH_BINARY_INV)
edges = cv2.Canny(thresh, 100, 200)
#cv2.imshow('original_image',image)
#cv2.imshow('2',thresh)
#cv2.imshow('3',edges)
#cv2.waitKey()
#cv2.destroyAllWindows()
contours,hierachy = cv2.findContours(edges, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
for contour in contours:
cv2.drawContours(image, [contour], -1, (0, 0, 255), 3)
cv2.imwrite(sys.argv[1]+".jpg", image)
imageFiles = Imageprocessing.readImages(sys.argv[1])
Imageprocessing.processImage(imageFiles)
一:
二:
三:
正如您所要求的,下面的代码将'在文件名下创建子文件夹,并将分段图像写入相关文件夹'。你知道吗
这将在指定为
sys.argv[2]
的位置为每个文件名创建一个文件夹,作为绘制轮廓的分段图像。你知道吗您可以调整
if w > 3 and h > 10:
中的“w”和“h”,或者调整内核,或者调整“cv2.deplate”中的迭代值,以将此代码调整为图像文件中不同大小的字符。(当前代码已调整到您提供的图像链接)相关问题 更多 >
编程相关推荐