Hence, the expected speedup might be less than expected. Here we will still need to do a lot of processing per pixel still. Notice, that using half the images, say 900 images, will only speed up 50%. Use fever images in our collection (use less than 1.885 images).There are various options to compromise for speed and we will not investigate all. The result is what can be expected by using this amount of images, but the performance is too slow to have a flowing smooth live webcam stream. There is one line to notice specifically. Total_sum = np.sum(np.where(roi > images, roi - images, images - roi)) Print("Process time", time.time()- start, "seconds") Return process(frame, images, box_height=12, box_width=16): While the performance is quite good, let us test it.įirst you need to import the time library. Step 5: Testing the performance and improve it by using Numba In this example we used 1.885 images to process it. Notice the average (mean) value is a float, hence, we can have more than 256 gray scale images. The process function takes and breaks down the image in blocks of 16×12 pixels, computes the average gray scale, and takes the estimated best match. The preprocessing function reads all the images, converts them to gray scale (to have only 1 channel per pixel), and returns them as a NumPy array to have optimized code. Images.append(cv2.cvtColor(img, cv2.COLOR_BGR2GRAY))ĭef process(frame, images, box_height=12, box_width=16): The second part is done in each iteration inside the process function.įiles = glob.glob(os.path.join(path, "*")) The first step is preprocessing and should be done before we enter the main loop of the webcam capturing. Fill out the processing of each frame, which replaces each 16×12 box of the frame with the best matching image.Loading all the images we need to use (the 16×12 gray scale images).We need to introduce two main things to create this simple video mosaic. This code will just generate a window that shows a gray scale image. The above code is just an empty shell where the function call to process is where the all the processing will be. # When everything done, release the capture Gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # If your webcam does not support 640 x 480, this will find another resolution What we need is to convert them all to gray scale and resize to fit our purpose. We have used photos from Pexels, which are all free for use without copyright. The first step is to collect images you want to use. To optimize performance we have chosen to make it in gray scale. The next question is, will it be efficient enough to have a live webcam stream processed? Step 2: Create a collection of small images For each pixel in photo P find the image I from C that has the closed average color as the pixel.Scale down the photo P you want to create a mosaic of.Have a collection C of small images used to create the photographic mosaic.A simple mosaic is when the original image is scaled down and each pixel is then exchanged with one small image with the same average color. The first thing we want to achieve is to create a simple mosaic. This is done in the above with the original frame of 640×480 pixels and the mosaic is constructed of small images of size 16×12 pixels. The idea is to generate the original image (photograph) by mosaic technique by a lot of smaller sampled images. Also, it is done in gray scale to improve performance. The above is not a perfect example of it as it is generated with speed to get it running smooth from a webcam stream. Step 1: How does simple photo mosaic work?Ī photographic mosaic is a photo generated by other small images. Then we will extend that to create a better quality video mosaic and try to improve the performance by lowering the quality. First we will learn the simple way to create a video mosaic and investigate the performance of that. We will investigate if we can create a decent video mosaic effect on a live webcam stream using OpenCV, Numba and Python.
0 Comments
Leave a Reply. |