Programmatically generate image layout [closed] - python

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 10 months ago.
Improve this question
I'd like to create a python script that would receive some text and photos, arrange and compose them following some rules, and output a final image. To do so, I would need a python library that could:
Read, scale and move pictures to create composite images.
Insert text and maybe some simple glyphs (circles, arrows)
Apply masks to images.
I've started using pycairo to that end, and while it is certainly very capable, it's rather slow and most certainly not the right tool for the job; it's vector graphics library, after all. There's Pillow as well, but I reckon it's too low-level.
Is there a python library better-suited to that task?

Opencv is the library that is used mostly in imaging solutions. I will post some templates for the people who might be looking for these functions.
1)Read, scale and move pictures to create composite images.
import cv2
cv2.imread("Image path")
cv2.resize(original image,size)
cv2.
is the way you can read an image in OpenCV. It is given to you as an array and with the resize function that should settle it out. For creating composite images, you can also do it with openCV as well here is a template I have gotten from here.
import numpy as np
import cv2
A = cv2.imread(r"C:\path\to\a.png", 0)
B = cv2.imread(r"C:\path\to\b.png", 0)
#C = cv2.merge((B,A,B))
C = np.dstack((B,A,B))
cv2.imshow("imfuse",C)
cv2.waitKey(0)
Insert text and maybe some simple glyphs (circles, arrows)
cv2.putText()
can definitely solve your issue. It takes the image and the text as an argument. For inserting glyphs there are some other functions for that. One of those which is:
cv2.arrowedLine()
Apply masks to images.
You can also apply masks to images. This is not a one liner here so I will leave a good link that I was relying on here.
For clarification as #martineau said you can do these with pillow but it might need some extra work on your part. And for the part that where you might need a smaller library you might consider using OpenCVlite but I haven't had any experience with it yet.

Related

How can I convert a grayscale video to RGB (jet colormap) in C# or Python? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 months ago.
Improve this question
I have a grayscale video that I'd like to convert and process to RGB using a jet colormap. Currently I'm pulling all of the frames out of the video using FFMPEG, locking the byte array of pixel data from each frame, pulling the pixels out and converting them to 8bit RGB using some mapping to a jet colormap and then streaming the new bitmaps to a video using FFMPEG.
The code is all in C# and works well enough, my issue is that with videos that have more than 2,000 frames or so it gets VERY slow.
Is there any efficient way that I can do what I'm attempting in either python or C#? Or do I need to venture into the world of GPU programming and shaders?
Thanks in advance!
You can certainly do it in Python, though I'm not sure about efficiency. It should be reasonably quick, though, as many big Python libraries are just wrappers for C++ libraries. OpenCV (aka cv2) is no exception, and color mapping with it in Python is super easy:
import cv2
# Read grayscale images and store as raw 2D arrays (hxw) in gray_images list
gray_images = [...]
for im_gray in gray_images:
im_color = cv2.applyColorMap(im_gray, cv2.COLORMAP_JET) # im_color = 3D (hxwx3) BGR image
See this webpage for more details.

Trying to read these plates using OCR but they are blurry. Where do I start? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed last year.
Improve this question
Hi I am a student doing research in my university. This is my first time using computer vision (openCV) and I am fairly new to image preprocessing. I have these images of License Plates and I would like to use easyOCR/pytesseract to read the plates. Currently all I have done is convert the image to grayscale, rotate it by a few degrees, but the reading results are very inconsistent. How do I improve that?
I have tried using kernels to sharpen the images but they seem to be fairly inconsistent too.
Here are some images I have to give you a general idea of what the images are like:
I would start with image enhancement. It's hard to tell what exactly is applicable but here are some possible manuevers:
As usual recognition algorithms are not invariant to rotation. And every image seems to be geometically distorted similarly. You can try to normalize the geometry by warpPerspective function from Opencv with appropriate transformation matrix. Rotation is a subset of all possible transformations covered by perspective transform.
You can try to use advanced deblurring techniques like wiener filter or deeplearning. It seems like point spread function is different from image to image that complecates the recovery.
There is some periodic signal in your images (vertical blue-white-blue stripes). That can possibly can be enhanced by doing FFT -> removing components of the specific wavelength -> iFFT.
Anyway looking on your images, I am not sure if it will be easy to achieve the desired result without diving into the OCR pipeline.

How to crop image based on contents (Python & OpenCV)? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Well currently I'm working on a personal project which is the identification of products in a scanned image taken from a store catalog.
As you may see in the image there's no lines separation between products, so using Hough lines to locate the products won't really solve the problem!
Using Tesseract is really amazing to extract the image content, the only problem that I'm facing is finding the image products automatically, I mean not cropping the image manually but I want to detect the products, cropping them with their text description and price and then extract content using OCR.
I have tried many image processing techniques but still nothing (I'm using Python and OpenCV).
Thanks in advance :)
The problem you have is usually called background removal, or alternatively foreground extraction. In this example, it might actually be relatively easy, as the background is mostly in shades of the same color - my recommendation would be to look at the GrabCut algorithm which is described here: https://docs.opencv.org/3.4.3/d8/d83/tutorial_py_grabcut.html

2D image projections to 3D Volume [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
I am looking for a library, example or similar that allows me to loads a set of 2D projections of an object and then converts it into a 3D volume.
For example, I could have 6 pictures of a small toy and the program should allow me to view it as a 3D volume and eventually save it.
The object I need to convert is very similar to a cylinder (so the program doesn't have to 'understand' what type of object it is).
There are several things you can mean, I think none of which currently exists in free software (but I may be wrong about that), and they differ in how hard they are to implement:
First of all, "a 3D volume" is not a clear definition of what you want. There is not one way to store this information. A usual way (for computer games and animations) is to store it as a mesh with textures. Getting the textures is easy: you have the photographs. Creating the mesh can be really hard, depending on what exactly you want.
You say your object looks like a cylinder. If you want to just stitch your images together and paste them as a texture over a cylindrical mesh, that should be possible. If you know the angles at which the images are taken, the stitching will be even easier.
However, the really cool thing that most people would want is to create any mesh, not just a cylinder, based on the stitching "errors" (which originate from the parallax effect, and therefore contain information about the depth of the pictures). I know Autodesk (the makers of AutoCAD) have a web-based tool for this (named 123-something), but they don't let you put it into your own program; you have to use their interface. So it's fine for getting a result, but not as a basis for a program of your own.
Once you have the mesh, you'll need a viewer (not view first, save later; it's the other way around). You should be able to use any 3D drawing program, for example Blender can view (and edit) many file types.

Create video with effects from image [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
I am currently working on a project where I generate several images and then transform them into a video.
I am using OpenCV for the whole image processing thing, and especially cv.WriteFrame.
Even though it is working quite well, I would like to add some effects for image transition.
Simple things in fact, I would like the images to blend into each other to avoid the "violent" way it is currently done.
I also have problems with the fps in cv.WriteFrames (which is not accurate).
I searched on the internet without finding any library/utility to do that, so I started thinking about implementing it by myself. It would be quite a hassle though.
Would you know about an option to do such a thing?
I am open to any solution !
Thanks
To have a smooth transition you most likely have to put some extra frames between the 2 images. Those extra frames could be the 2 images progressively adding each other.
Usually opencv addWeighted is used to blend 2 images, it has parameters to set the weights.
addWeighted docs:
http://docs.opencv.org/modules/core/doc/operations_on_arrays.html#addweighted
Well, I've never worked with OpenCV, but if you want to do a fade in or fade out I could envision doing something like creating frames that have progressively more alpha transparency and adding them into the stack thats being written to the video file. Something like that could be done in just a few lines of code with PIL.

Categories