opencv | Open Source Computer Vision Library | Computer Vision library
kandi X-RAY | opencv Summary
kandi X-RAY | opencv Summary
Open Source Computer Vision Library
Top functions reviewed by kandi - BETA
opencv Key Features
opencv Examples and Code Snippets
Trending Discussions on opencv
I inherited an application with opencv, shiboken and pyside and my first task was to update to qt6, pyside6 and opencv 4.5.5. This has gone well so far, I can import the module and make class instances etc. However I have a crash when passing numpy arrays:
I am passing images in the form of numpy arrays through python to opencv and I am using
pyopencv_to to convert from the array to
cv::Mat. This worked in a previous version of opencv (4.5.3), but with 4.5.5 it seems to be broken.
When I try to pass an array through
pyopencv_to, I get the exception
opencv_ARRAY_API was nullptr. My predecessor solved this by directly calling
PyInit_cv2(), which was apparently previously included via a header. But I cannot find any header in the git under the tag 4.5.3 that defines this function. Is this a file that is generated? I can see there is a
pycompat.hpp, but that does not include the function either.
Is there a canonical way to initialize everything so that numpy arrays can be passed properly? Or a tutorial anyone can point me to? My searches have so far not produced any useful hints.
Thanks a lot in advance! :)...
ANSWERAnswered 2022-Apr-05 at 12:36
I finally found a solution. I dont know if this is the correct way of doing it, but it works.
I made a header file that contains
I have source (
src) image(s) I wish to align to a destination (
dst) image using an Affine Transformation whilst retaining the full extent of both images during alignment (even the non-overlapping areas).
I am already able to calculate the Affine Transformation rotation and offset matrix, which I feed to
scipy.ndimage.interpolate.affine_transform to recover the
The problem is that, when the images are not fuly overlapping, the resultant image is cropped to only the common footprint of the two images. What I need is the full extent of both images, placed on the same pixel coordinate system. This question is almost a duplicate of this one - and the excellent answer and repository there provides this functionality for OpenCV transformations. I unfortunately need this for
Much too late, after repeatedly hitting a brick wall trying to translate the above question's answer to
scipy, I came across this issue and subsequently followed to this question. The latter question did give some insight into the wonderful world of
scipy's affine transformation, but I have as yet been unable to crack my particular needs.
The transformations from
dst can have translations and rotation. I can get translations only working (an example is shown below) and I can get rotations only working (largely hacking around the below and taking inspiration from the use of the
reshape argument in
scipy.ndimage.interpolation.rotate). However, I am getting thoroughly lost combining the two. I have tried to calculate what should be the correct
offset (see this question's answers again), but I can't get it working in all scenarios.
Translation-only working example of padded affine transformation, which follows largely this repo, explained in this answer:...
ANSWERAnswered 2022-Mar-22 at 16:44
If you have two images that are similar (or the same) and you want to align them, you can do it using both functions rotate and shift :
In the image below, I am using opencv harris corner detector to detect only the corners for the squares (and the smaller squares within the outer squares). However, I am also getting corners detected for the numbers on the side of the image. How do I get this to focus only on the squares and not the numbers? The code, input image and output image are below:...
ANSWERAnswered 2022-Mar-28 at 00:09
Here's a potential approach using traditional image processing:
Obtain binary image. We load the image, convert to grayscale, Gaussian blur, then adaptive threshold to obtain a black/white binary image. We then remove small noise using contour area filtering. At this stage we also create two blank masks.
Detect horizontal and vertical lines. Now we isolate horizontal lines by creating a horizontal shaped kernel and perform morphological operations. To detect vertical lines, we do the same but with a vertical shaped kernel. We draw the detected lines onto separate masks.
Find intersection points. The idea is that if we combine the horizontal and vertical masks, the intersection points will be the corners. We can perform a bitwise-and operation on the two masks. Finally we find the centroid of each intersection point and highlight corners by drawing a circle.
Here's a visualization of the pipeline
-> binary image
Detected horizontal lines
-> horizontal mask
Detected vertical lines
-> vertical mask
Bitwise-and both masks
-> detected intersection points
-> cleaned up corners
The results aren't perfect but it's pretty close. The problem comes from the noise on the vertical mask due to the slanted image. If the image was centered without an angle, the results would be ideal. You can probably fine tune the kernel sizes or iterations to get better results.
I am trying to remove horizontal lines from my daughter's drawings, but can't get it quite right.
The approach I am following is creating a mask with horizontal lines (https://stackoverflow.com/a/57410471/1873521) and then removing that mask from the original (https://docs.opencv.org/3.3.1/df/d3d/tutorial_py_inpainting.html).
As you can see in the pics below, this only partially removes the horizontal lines, and also creates a few distortions, as some of the original drawing horizontal-ish lines also end up in the mask.
Any help improving this approach would be greatly appreciated!Create mask with horizontal lines
ANSWERAnswered 2022-Mar-14 at 16:58
Get the Edges
Dilate to close the lines
Hough line to detect the lines
Filter out the non horizontal lines
Inpaint the mask
Getting the Edges
ANSWERAnswered 2022-Jan-09 at 10:19
The new version of OpenCV has some issues. Uninstall the newer version of OpenCV and install the older one using:
I have pretrained model for object detection (Google Colab + TensorFlow) inside Google Colab and I run it two-three times per week for new images I have and everything was fine for the last year till this week. Now when I try to run model I have this message:...
ANSWERAnswered 2022-Feb-07 at 09:19
It happened the same to me last friday. I think it has something to do with Cuda instalation in Google Colab but I don't know exactly the reason
Error while installing manimce, I have been trying to install manimce library on windows subsystem for linux and after running...
ANSWERAnswered 2022-Jan-28 at 02:24
apt-get install sox ffmpeg libcairo2 libcairo2-dev apt-get install texlive-full pip3 install manimlib # or pip install manimlib
I have this image for a treeline crop. I need to find the general direction in which the crop is aligned. I'm trying to get the Hough lines of the image, and then find the mode of distribution of angles.
I've been following this tutorialon crop lines, however in that one, the crop lines are sparse. Here they are densely pack, and after grayscaling, blurring, and using canny edge detection, this is what i get...
ANSWERAnswered 2022-Jan-02 at 14:10
You can use a 2D FFT to find the general direction in which the crop is aligned (as proposed by mozway in the comments). The idea is that the general direction can be easily extracted from centred beaming rays appearing in the magnitude spectrum when the input contains many lines in the same direction. You can find more information about how it works in this previous post. It works directly with the input image, but it is better to apply the Gaussian + Canny filters.
Here is the interesting part of the magnitude spectrum of the filtered gray image:
The main beaming ray can be easily seen. You can extract its angle by iterating over many lines with an increasing angle and sum the magnitude values on each line as in the following figure:
Here is the magnitude sum of each line plotted against the angle (in radian) of the line:
Based on that, you just need to find the angle that maximize the computed sum.
Here is the resulting code:
I'm trying to detect angle difference between two circular objects, which be shown as 2 image below.
I'm thinking about rotate one of image with some small angle. Every time one image rotated, SSIM between rotated image and the another image will be calculated. The angle with maximum SSIM will be the angle difference.
But, finding the extremes is never an easy problem. So my question is: Are there another algorithms (opencv) can be used is this case?
Thanks @Micka, I just do the same way he suggest and remove black region like @Yves Daoust said to improve processing time. Here is my final result:
ORIGINAL IMAGE ROTATED + SHIFTED IMAGE...
ANSWERAnswered 2021-Dec-15 at 09:19
Here's a way to do it:
- detect circles (for the example I assume circle is in the image center and radius is 50% of the image width)
- unroll circle images by polar coordinates
- make sure that the second image is fully visible in the first image, without a "circle end overflow"
- simple template matching
Result for the following code:
I'm working on CI for my Python + Django project. I have to use the
python:3.9-alpine image. A weird error is popping in my CI pipelines:
ANSWERAnswered 2021-Dec-05 at 17:35
What is the reason of my error?
Did you read my previous answer to a similar question of yours? The last part warns about certain combinations of Alpine + Python and this seems to be happening right now.
I tried to replace psycopg2 with psycopg2-binary but have the same error
The problem here might be a python library that has dependencies on
gcc, which is not shipped on alpine by default.
Try replacing this:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge ItemsFind more libraries
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page