Skip to content

Commit

Permalink
Created a multithreading way to process images
Browse files Browse the repository at this point in the history
  • Loading branch information
nikkonrom committed Nov 30, 2017
1 parent 696e36c commit 3994eb8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions imager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from PyQt5 import Qt, QtWidgets
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QFileDialog
from boundaries import BoundariesOperation
from semantic_segmentation import SemanticSegmentation
from mainwindow import *
from operation import qpixmap_to_pil_image
from operation import image_to_qimage
from boundaries import BoundariesOperation
from semantic_segmentation import SemanticSegmentation
from saliency import Saliency
from face_recognition_ import FaceRecognition

Expand Down
34 changes: 34 additions & 0 deletions multiprocessing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import threading
from multiprocessing import Queue
from PIL import Image
from boundaries import BoundariesOperation

class Worker(threading.Thread):
def __init__(self, work_queue, func):
super(Worker, self).__init__()
self.work_queue = work_queue
self.func = func

def run(self):
try:
filename = self.work_queue.get()
self.process(filename)
finally:
pass

def process(self, filename):
savenamelist = filename.split('.')
savename = savenamelist[0] + '_out' + filename[1]
image = Image.open(filename)
out_image = self.func(image)
out_image.save(savename)

def execute_processing(filelist, func):
work_queue = Queue()
for filename in filelist:
work_queue.put(filename)
for i in range(4):
worker = Worker(work_queue, func)
worker.start()


0 comments on commit 3994eb8

Please sign in to comment.