OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Sat, 28 Dec 2019 07:21:39 -0600Assertion failed (!fixedType() || ((Mat*)obj)->type() == mtype) in cv::_OutputArray::create while Performing DFThttp://answers.opencv.org/question/224053/assertion-failed-fixedtype-matobj-type-mtype-in-cv_outputarraycreate-while-performing-dft/I am trying to perform DFT on two images such that I get a full size complex valued spectrum.
In order to achieve that I have written following code:
cv::Mat_<std::complex<float>> DFTReal2Complex(const cv::Mat_<float>& input)
{
cv::Mat_<float> result = cv::Mat::zeros(input.size(), input.type());
cv::dft(input, result, cv::DFT_COMPLEX_OUTPUT); //,
return result;
}
When I execute the code, I get an exception
Assertion failed (!fixedType() || ((Mat*)obj)->type() == mtype) in cv::_OutputArray::create, file C:\builds\master_PackSlave-win64-vc12-shared\opencv\modules\core\src\matrix.cpp, line 2130.
If I remove DFT_COMPLEX_OUTPUT flag, the code executes fine but am looking for a complex valued spectrum.
1. Am I using DFT_COMPLEX_OUTPUT flag in a wrong way? Is there another way to do this
2. Is there any way to get a complex valued spectrum in an alternate way?Anupama RajkumarSat, 28 Dec 2019 07:21:39 -0600http://answers.opencv.org/question/224053/Speed up DFT by specifying ROI in frequency domainhttp://answers.opencv.org/question/191988/speed-up-dft-by-specifying-roi-in-frequency-domain/*Note: This question is also asked at [Stack Overflow](https://stackoverflow.com/questions/50521283/how-to-accelerate-dft-by-specifying-region-of-interest-in-frequency-domain) a couple of days later since this post.*
I'm building an application which extensively use dft, discrete Fourier transform. I'm trying to speed up so as to run in real-time.
In that application I only use a part of dft output specified by a rectangular ROI. My current implementation follows the steps below:
1. Compute dft of the input image *f* (typically size of 512x512) and get the entire dft result *F*
2. Crop *F* into a pre-specified ROI (typically size of 32x32, located arbitrary), *R*
This process basically works well, but involves useless calculation since I only need partial information of *F*. I'm looking for a way to accelerate this calculation only by computing necessary part of dft.
I found OpenCV with Intel IPP computes dft with Intel IPP functions, which results in an order of magnitude faster than naive OpenCV implementation. I'm wondering if I can even accelerate this computation by only computing necessary frequency domain of dft.
Since I'm new to OpenCV, I've lost my way here, so I hope you could provide a way to do this.
Kindly note that I don't mean to do a dft to an ROI of an image, i.e. *dft(ROI(f))*, but I want to compute *ROI(dft(f))*.
Thanks in advance.
**EDIT**: I've got a nice answer on Stack Overflow. Refer to the URL as pointed in the main text.masahiro.dllMon, 21 May 2018 03:26:55 -0500http://answers.opencv.org/question/191988/How to find rectangle edges from image and crop image from it's edges?http://answers.opencv.org/question/191392/how-to-find-rectangle-edges-from-image-and-crop-image-from-its-edges/Hello,
I am developing an application for detect driving license and capture image of driving license using surface view and and crop from those it's four corner using openCV.
so right now i am using canny edge detection and find the edges but i am not able to crop the image because canny edge detection return black and white image i am crop my original license image from it's edges.
Please suggest me any best solution.Akhil PatelSat, 12 May 2018 01:33:30 -0500http://answers.opencv.org/question/191392/Accuracy of OpenCV's DFT (C++ implementation)http://answers.opencv.org/question/182729/accuracy-of-opencvs-dft-c-implementation/I'm coding a with C++ and OpenCV. I'm comparing the outputs (complex numbers) of MATLAB's FFT function and OpenCV's DFT function. I am able to get identical results for normal images such as the one below (Fig. 1). However, after some processing to get the image (Fig. 2), the values are very different by orders of magnitude and I think the OpenCV's output is wrong.
Is this expected of the OpenCV's DFT function? I've tried all sorts of things like putting "DFT_SCALE" as well. Any suggestions please? Thanks!
![Fig.1](/upfiles/15162731822390162.jpg)
![Fig.2](/upfiles/15162732072692394.jpg)
I've also included my MATLAB code. Fig.1 is the variable assigned "S" and Fig.2 is the variable "Normin2". (product of imshow(Normin2)). Normin2 has a maximum value of 1.359 and a minimum value of -1.2667.
![MATLAB code](/upfiles/15162755494912427.jpg)Colin PeerisThu, 18 Jan 2018 05:08:08 -0600http://answers.opencv.org/question/182729/opencv idft output and calculation of phasehttp://answers.opencv.org/question/56345/opencv-idft-output-and-calculation-of-phase/ I have been trying to calculate the phase information of a complex matrix in opencv. As I am new in using opencv I am sure I am failing to look for the correct answer. So, I have this program.
I am sure the matrix invDFT holds complex values.
So what is the easiest way of calculating the phase of the total matrix? And how can I imshow the DFT output for this program? I have used phase and I am not sure if its correct.
Thanks. I already said I am new in opencv. So please pardon if my questions are too basic. Thanks once again.
int main()
{
// Read image from file
// Make sure that the image is in grayscale
Mat img = imread("input.bmp", 0);
Mat mag, ph;
Mat planes[] = { Mat_<float>(img), Mat::zeros(img.size(), CV_32F) };
Mat complexI; //Complex plane to contain the DFT coefficients {[0]-Real,[1]-Img}
merge(planes, 2, complexI);
dft(complexI, complexI); // Applying DFT
// Reconstructing original imae from the DFT coefficients
Mat invDFT, invDFTcvt;
idft(complexI, invDFT, DFT_SCALE | DFT_REAL_OUTPUT); // Applying IDFT
Mat planesi[] = { Mat_<float>(invDFT), Mat::zeros(invDFT.size(), CV_32F) };
split(invDFT, planesi);
invDFT.convertTo(invDFTcvt, CV_8U);
imshow("Output", invDFTcvt);
phase(planesi[0], planesi[1], ph, false);
namedWindow("phase image", CV_WINDOW_AUTOSIZE);
imshow("phase image", ph);
//show the image
imshow("Original Image", img);
// Wait until user press some key
waitKey(0);
return 0;
}tahseen_kamalThu, 26 Feb 2015 22:20:13 -0600http://answers.opencv.org/question/56345/Apply notch filter on imagehttp://answers.opencv.org/question/5032/apply-notch-filter-on-image/How can I apply a notch filter on an image using OpenCV 2.4 and C++? I want to calculate the DFT of an image, suppress certain frequencies and calculate reverse dft.
Can anyone show me some sample code how to apply a notch filter in frequecy domain?tobydMon, 10 Dec 2012 04:28:42 -0600http://answers.opencv.org/question/5032/