Opencv Mosaic from video - c++

I need to do the same thing of this video https://youtu.be/59RJeLlDAxQ but in Opencv. For now I'm doing this thing http://ramsrigoutham.com/2012/11/22/panorama-image-stitching-in-opencv/ with a little modify in the final image merging, but it doesn't work very well. How can I proceed?
EDIT
For testing I'm using the video lab from this page http://www.cs.ucsb.edu/~holl/CS290I/Assignments/Assignments-3/Assignment3Mosaicing.html
I ran my code on that video and I obtain this:
It's not very accurate but its ok.If I let the program run, at a certain point my stitcher produce this:
.
For the stitching ROIs instead of the ramsrigoutham.com ones I'm using this:
warpPerspective(current_frame, rImg, H, Size(current_frame.cols, current_frame.rows), INTER_NEAREST);
Mat roi1(final_img, Rect(img_loop.cols, img_loop.rows, vImg[1].cols, vImg[1].rows));
Mat roi2(final_img, Rect(img_loop.cols, img_loop.rows, rImg.cols, rImg.rows));
rImg.copyTo(roi2);
vImg[1].copyTo(roi1);

Why not using: http://docs.opencv.org/modules/stitching/doc/high_level.html#stitcher-composepanorama
It's available on 2.4.11 and 3.0.0.

The link you mentioned is access deniedhttp://www.cs.ucsb.edu/~holl/CS290I/Assignments/Assignments-3/Assignment3Mosaicing.html
.
what are 'img_loop' and 'Vimg' and 'rimg' in your code? there is some difference between your code and the code you linked.if it is possible explain a little so I can work on your problem , cause Im doing the same thing in opencv

Related

view cv::Mat data while debugging in Visual Studio Code

I need to check elements of some cv::Mats while debugging my OpenCV C++ code.
Tried adding mymat.at<double>(0, 0) to watch but there are two problems:
Sometimes it doesn't work: Couldn't find method cv::Mat::at<double>
Even if it works, it is very hard to check elements one by one.
Currently, I write Mat contents to a file using cv::FileStorage but it is not a good solution also.
Is there any VSCode extension like Image Watch to show value of Mat elements while debugging?

OPENCV - How to use Haar cascade Github xml files in OpenCV?

I am starting to learn object detection in OpenCV 3.4.2 (.Net C++ 2017).
I am very interested in detecting strawberries in pictures (at the moment I am really interested in detecting just strawberries). I know OpenCV has some pre-trained Haar cascade files in OpenCV directory, but there are not .xml files for strawberries (there are for body parts instead).
So I decided to search on Google, to try to find trained strawberry Haar cascade .xml files. I found this .xml file XML strawberry file but I get error -49 when I try to execute the program. I have executed correctly the program using OpenCV files, but I cannot execute correctly when I try with GitHub XML file.
I have found this thread here on StackOverflow StackOverFlow thread about GitHub XML files in OpenCV and a user claims that it's not possible to use GitHub XML files into OpenCV.
My question is about if there is a way to use the XML GitHub file I have posted in this thread in OpenCV or I need to train my own XML file? I would like to use GitHub file.
Edit(1)
I have found this link strawberry detection in OpenCV where, if you look at the source code, it seems that the same strawberry_classifier.xml is being used. I don't know if the name of the file is just a coincidence (Github filename and the filename shown in the source code of the 3rd link are exactly the same). At least it seems that the programmer (from the 3rd link) has obtained some results while using the (apparently) same .xml file that I want to use. But I don't know how to use that strawberry_classifier.xml file.
Python dev here,
I'm late, but in case anyone still wants to see an answer:
The classifier from GitHub works perfectly fine as shown in this Python code (Sorry, I didn't do it in C++, but I think it won't be much different)
The script uses your webcam as the image source. You can show the webcam some images of strawberries, and it will recognize it:
import cv2 #import library
#define Haar Cascade Classifier
Strawberry_Classifier = cv2.CascadeClassifier(r"C:\Users\Strawberry.xml")
VideoCapture = cv2.VideoCapture(0) #capture video from camera
#set video size
VideoCapture.set(3, 540)
VideoCapture.set(4, 360)
while True:
#Connect video and convert
Connection_Success, Video = VideoCapture.read() #returns a bool and video array in one tuple (sucess, video array)
RGB_video = cv2.cvtColor(Video, cv2.COLOR_BGR2RGB) #converts to suitable format
Detect_Strawberry = Strawberry_Classifier.detectMultiScale(RGB_video, 1.3, 13) #MODIFY THIS FOR LESS/MORE DETECTION ACCURACY
#Detect Strawberry
for(x,y,w,h) in Detect_Strawberry: #x,y width, height
cv2.rectangle(Video, (x, y), (x + w, y + h), (0, 255, 0), 3) #Put a rectangle around Strawberry
cv2.imshow("Window", Video) #show video
#quit if q is pressed, quit
QuitKey = cv2.waitKey(30)
if QuitKey == ord("q"):
VideoCapture.release()
cv2.destroyAllWindows()

OpenCV imwrite params read access violation

A very simple question...why am I getting a read access violation error with this code?
cv::Mat laserSpeckle = Mat::zeros(100,100,CV_8UC1);
imwrite( "C://testimage.jpg", laserSpeckle );
When i attach a debugger and look into it further, it throws the exception at this snippet in grfmt.cpp.
if( params[i] == CV_IMWRITE_JPEG_QUALITY )
{
quality = params[i+1];
quality = MIN(MAX(quality, 0), 100);
}
It occurs with .png and .tiff too. Im an OpenCV newbie, my apologies if this is something really simple. I am using Qt for what its worth.
Do you build OpenCV yourself? If yes, make sure that the option WITH_JPEG is enabled when you configure your build files:
cmake ... -DWITH_JPEG=ON ...
If you want to save image with alpha channel you should use png format. It is described here
It should work with bmp format:
cv::Mat laserSpeckle = cv::Mat::zeros(100,100,CV_8UC1);
cv::imwrite( "C://testimage.bmp", laserSpeckle );
Your code also works on my computer. However, it seems that on some systems it works only for bmp images. I saw similar issues reported here and here.
The problem is with the debugger version (x64) if you build the code using the release version (x64) it works fine for me.
In my case c++ Code Generation settings were wrong
Should have been Multithreaded DEBUG dll MD

Opencv cvThreshold bug

Hello I don t know if I am doing something wrong or not but when I do the following:
IplImage *testimage;
testimage = cvCreateImage(cvSize(10,10),IPL_DEPTH_8U,1);
cvThreshold(testimage,testimage,127,127,CV_THRESH_TRUNC);
everything works fine then when I try to use unsigned short values:
IplImage *testimage;
testimage = cvCreateImage(cvSize(10,10),IPL_DEPTH_16U,1);
cvThreshold(testimage,testimage,127,127,CV_THRESH_TRUNC);
my program crashes... I use opencv 2.4.2 I think this could maybe be a bug in opencv.
Somehow if I try the following:
IplImage *testimage;
testimage = cvCreateImage(cvSize(10,10),IPL_DEPTH_16S,1);
cvThreshold(testimage,testimage,127,127,CV_THRESH_TRUNC);
it doesn t crash anymore
It is not crashing. It is throwing an exception and since you are not catching it, your program is aborting.
OpenCV Thresholding does not support 16U.
The supported ones are: 8U, 16S and 32F
See the OpenCV documentation for function threshold. The first parameter is 8 or 32 bit image
P.S. In crash message you should see the reason for crashing

Application crashes on equalizeHist of OpenCV

My MFC app runs various API from OpenCV2. Everything else is working fine. But when my program runs
cv::Mat result;
cv::equalizeHist(m_cvImage,result);
I get following runtime exception.
Unhandled exception at 0x7727fbae in OpenCVTest.exe: Microsoft C++ exception: cv::Exception at memory location 0x0029e944..
"C:\slave\WinInstallerMegaPack\src\opencv\modules\imgproc\src\histogram.cpp:2430: error: (-215) CV_ARE_SIZES_EQ(src, dst) && CV_ARE_TYPES_EQ(src, dst) && CV_MAT_TYPE(src->type) == CV_8UC1"
According to debugger, the exception was thrown in the middle of processing (about 40%) the image in equalizeHist. Is there anything I need to do? FYI: I am using binary OpenCV provided by its web site.
UPDATE:
I've resolved this issue by converting images to gray-level before equalizing it. I just didn't know
the function only works with gray-level image
images that look like gray-level can be non-gray.
I imagine the problem you are encountering is that m_cvImage is a 3-channel image. So, you need to convert it to a grayscale image before you can call equalizeHist.
cvtColor(m_cvImage, m_cvImage, CV_BGR2GRAY);
cv::Mat result;
cv::equalizeHist(m_cvImage, result);
Also, have a look at the EqualizeHist_Demo.cpp tutorial sample to see how it is used.