OpenCV | Learning OpenCV | Computer Vision library
kandi X-RAY | OpenCV Summary
kandi X-RAY | OpenCV Summary
OpenCV C++ Builds with Qt Support.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Blurise an image
- Gets the gradient of the camera
- Perform the thresholding algorithm
- Normalise image
- White out white balance
- Convert radians to degrees
- Finds the contour of the image
- Get the top left corner of a box
- Get the box of a given area
- Check if cnt is a rectangle
- Creates filter chain image
- R Check the target X axis
- Gets the range bearing
- Convert an image to HSV
- White balance image
- Get all centroid from img
- Compute the morphology of an image
- Calculate the angle in radians
- Normalize angle
OpenCV Key Features
OpenCV Examples and Code Snippets
Community Discussions
Trending Discussions on OpenCV
QUESTION
While studying OpenCV, I realized that whenever I blend two images the colors of scr2 have changed in some way(depends on the colors of scr1).
I know this is not an informative and clear way to explain my issue, however; I don't know how to describe this issue since I have no expertise with colors so I would like to show you what I meant with images and code.
The input image: Input image
...ANSWER
Answered 2021-Jun-15 at 16:46I think I misunderstood your issue. If your issue is that the image where you do not have lines has changed, then that is because you used a white background for scr2. The white then mixes with your image in the output. Make it scr2=img.copy() in place of what you have now. Then try your code. So in Python/OpenCV as a demonstration, using the Lena image as background, here is your code:
QUESTION
I tried 5 different implementations of the Sobel operator in Python, one of which I implemented myself, and the results are radically different.
My questions is similar to this one, but there are still differences I don't understand with the other implementations.
Is there any agreed on definition of the Sobel operator, and is it always synonymous to "image gradient"?
Even the definition of the Sobel kernel is different from source to source, according to Wikipedia it is [[1, 0, -1],[2, 0, -2],[1, 0, -1]]
, but according to other sources it is [[-1, 0, 1],[-2, 0, 2],[-1, 0, 1]]
.
Here is my code where I tried the different techniques:
...ANSWER
Answered 2021-Jun-15 at 14:22according to wikipedia it's [[1, 0, -1],[2, 0, -2],[1, 0, 1]] but according to other sources it's [[-1, 0, 1],[-2, 0, 2],[-1, 0, 1]]
Both are used for detecting vertical edges. Difference here is how these kernels mark "left" and "right" edges.
For simplicity sake lets consider 1D example, and let array be
[0, 0, 255, 255, 255]
then if we calculate using padding then
- kernel
[2, 0, -2]
gives[0, -510, -510, 0, 0]
- kernel
[-2, 0, 2]
gives[0, 510, 510, 0, 0]
As you can see abrupt increase in value was marked with negative values by first kernel and positive values by second. Note that is is relevant only if you need to discriminate left vs right edges, when you want just to find vertical edges, you might use any of these 2 aboves and then get absolute value.
QUESTION
According to the OpenCV Docs, we can use cv::FileStorage
to read/write custom data structure from/to config files (XML, YAML, JSON):
ANSWER
Answered 2021-Jun-15 at 15:05The issue is due to the intruduction of namespace, indeed you can get a similar issue with this code:
QUESTION
The documentation for convertMaps
says that it supports the following transformation:
(CV_32FC1, CV_32FC1)→(CV_16SC2, CV_16UC1)
This is the most frequently used conversion operation, in which the original floating-point maps (seeremap
) are converted to a more compact and much faster fixed-point representation. The first output array contains the rounded coordinates and the second array (created only whennninterpolation=false
) contains indices in the interpolation tables.
I understand that (CV_32FC1, CV_32FC1)
is encoding (x, y)
coordinates as floats. How does the fixed point format work? What is encoded in each 2-channel entry of the CV_16SC2
matrix? What interpolation tables does the CV_16UC1
matrix index into?
ANSWER
Answered 2021-Jun-14 at 23:34I'm going by what I remember from the last time I investigated this. Grain of salt and all that.
the fixed point format splits the integer and fractional parts of your (x,y)-coordinates into different maps.
it's "compact" in that CV_32FC2
or 2x CV_32FC1
uses 8 bytes per pixel, while CV_16SC2 + CV_16UC1
uses 6 bytes per pixel. also it's integer-only, so using it can free up floating point compute resources for other work.
the integer parts go into the first map, which is 2-channel. no surprises there.
the fractional parts are converted to 5-bit integers, i.e. they're multiplied by 32. then they're packed together, lowest 5 bits from one coordinate, higher next 5 bits from the other one.
the resulting funny number has a range of 0 .. 1023
, or 0b00000_00000 .. 0b11111_11111
, which encodes fractional parts (0.0, 0.0) and (0.96875, 0.96875) respectively (that's 31/32).
during remap...
the integer map is used to look up, for every resulting pixel, several pixels in the source image required for interpolation.
the fractional map is taken as an index into an "interpolation table", which is internal to OpenCV. it contains whatever factors and shifts required to correctly blend the several sampled pixels into one resulting pixel, all using integer math. I guess there are multiple tables, one for each interpolation method (linear, cubic, ...).
QUESTION
I am coding a program in OpenCV where I want to adjust camera position. I would like to know if there is any metric in OpenCV to measure the amount of perspectiveness in two images. How can homography be used to quantify the degree of perspectiveness in two images as follows. The method that comes to my mind is to run edge detection and compare the parallel edge sizes but that method is prone to errors.
...ANSWER
Answered 2021-Jun-14 at 16:59As a first solution I'd recommend maximizing the distance between the image of the line at infinity and the center of your picture.
Identify at least two pairs of lines that are parallel in the original image. Intersect the lines of each pair and connect the resulting points. Best do all of this in homogeneous coordinates so you won't have to worry about lines being still parallel in the transformed version. Compute the distance between the center of the image and that line, possibly taking the resolution of the image into account somehow to make the result invariant to resampling. The result will be infinity for an image obtained from a pure affine transformation. So the larger that value the closer you are to the affine scenario.
QUESTION
I am trying to use thrust with Opencv classes. The final code will be more complicated including using device memory but this simple example does not build successfully.
...ANSWER
Answered 2021-Jun-14 at 14:06As pointed out in the comments, for the code you have shown, you are getting a warning and this warning can be safely ignored.
For usage in CUDA device code:
For a C++ class to be usable in CUDA device code, any relevant member functions that will be used explicitly or implicitly in CUDA device code, must be marked with the __device__
decorator. (There are a few exceptions e.g. for defaulted constructors which don't apply here.)
The OpenCV class you are attempting to use (cv::KeyPoint
), doesn't meet these requirements for use in device code. It won't be usable as-is.
There may be a few options:
Recast your work using
cv::KeyPoint
to use some class that provides similar functionality, that you write yourself, in such a way as to be properly designed and decorated.Perhaps see if OpenCV built with CUDA has an alternate version here (properly designed/decorated) (my guess would be it probably doesn't)
Rewrite OpenCV itself, taking into account all necessary design changes to allow the
cv::KeyPoint
class to be usable in device code.As a variant of suggestion 1, copy the relevant data
.response
to a separate set of classes or just a bare array, and do your selection work based on that. The selection work done there can be used to "filter" the original array.
QUESTION
I'm trying to load a .npy
file and resize it with cv2.resize
but I get the following error message:
cv2.error: OpenCV(4.5.1-dev) /home/name/opencv_build/opencv/modules/imgproc/src/resize.cpp:3688: error: (-215:Assertion failed) !dsize.empty() in function 'resize'
This is my code:
...ANSWER
Answered 2021-Jun-14 at 07:05images in opencv should only have 2 dim if grayscale/single channel or 3 dim if color. you seem to have a gray/single channel image [192,640] thats wrapped in 2 lists [1,1,---]
so to get the image you need to get it from inside those 2 lists.
img = np.load(filepath)[0][0]
or if you are not sure how many lists its wrapped in, you can do
img = np.squeeze(np.load(filepath)
but that will work as long as there is only 1 image in those lists
QUESTION
I'm using the OpenCV function findChessboardCorners()
successfully, but I'm confused by the shape of the corners
return value.
Here is my code below. I already know that my chessboard image has 8 x 6 internal corners.
...ANSWER
Answered 2021-Jun-14 at 06:34It is an unwanted and unnecessary dimension, you can eliminate the dimension by using the squeeze function of numpy
:
QUESTION
I'm trying to run this code but it did not because I am not able to download this file from GitHub. Is there anyone who knows how I can download this file?
This is the link to the file with the filename face-trainner.yml
: https://github.com/codingforentrepreneurs/OpenCV-Python-Series/tree/…
I'm getting this error when running my program:
...ANSWER
Answered 2021-Jun-12 at 21:14Go to the main section of the GitHub repository: https://github.com/codingforentrepreneurs/OpenCV-Python-Series
- Press the code button and then download as zip.
- Unzip the file in your downloads.
- Navigate to
src/recognisers
and the fileface-trainner.yml
should be there. - Use that file how you want in your project (discard of the rest if you have no need for it).
Also make sure that you have typed the correct file name in your program with the two 'n's (face-trainner.yml
not face-trainer.yml
)
QUESTION
i'm trying to track objects with Optical flow in android after using a Haar Cascade detection like in the code below and i have this error can anyone help me with this
...E/cv::error(): OpenCV(3.4.12) Error: Assertion failed ((npoints = prevPtsMat.checkVector(2, CV_32F, true)) >= 0) in virtual void cv::{anonymous}::SparsePyrLKOpticalFlowImpl::calc(cv::InputArray, cv::InputArray, cv::InputArray, cv::InputOutputArray, cv::OutputArray, cv::OutputArray), file /build/3_4_pack-android/opencv/modules/video/src/lkpyramid.cpp, line 1259 E/org.opencv.video: video::calcOpticalFlowPyrLK_15() caught cv::Exception: OpenCV(3.4.12) /build/3_4_pack-android/opencv/modules/video/src/lkpyramid.cpp:1259: error: (-215:Assertion failed) (npoints = prevPtsMat.checkVector(2, CV_32F, true)) >= 0 in function 'virtual void cv::{anonymous}::SparsePyrLKOpticalFlowImpl::calc(cv::InputArray, cv::InputArray, cv::InputArray, cv::InputOutputArray, cv::OutputArray, cv::OutputArray)' E/AndroidRuntime: FATAL EXCEPTION: Thread-2 Process: opencv.org, PID: 31380 CvException [org.opencv.core.CvException: cv::Exception: OpenCV(3.4.12) /build/3_4_pack-android/opencv/modules/video/src/lkpyramid.cpp:1259: error: (-215:Assertion failed) (npoints = prevPtsMat.checkVector(2, CV_32F, true)) >= 0 in function 'virtual void cv::{anonymous}::SparsePyrLKOpticalFlowImpl::calc(cv::InputArray, cv::InputArray, cv::InputArray, cv::InputOutputArray, cv::OutputArray, cv::OutputArray)' ]
ANSWER
Answered 2021-Jun-12 at 22:56matPrevGray
is empty. that's what it's saying.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install OpenCV
You can use OpenCV like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page