Stereo with openCV - c++

I try to find the distance between camera and an object,so I use two different cameras (stereo). I use the program in opencv samples .
#include "opencv2/core/core.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include "opencv2/contrib/contrib.hpp"
#include <stdio.h>
#include <string.h>
#include<iostream>
using namespace cv;
const char *windowDisparity = "Disparity";
int main( )
{
Size S(640,360);
Mat threshold2,threshold1;
Mat imgLeft = imread( "lift.jpg", CV_LOAD_IMAGE_GRAYSCALE );
Mat imgRight = imread("right.jpg", CV_LOAD_IMAGE_GRAYSCALE );
resize(imgLeft,imgLeft,S);
Mat imgDisparity16S = Mat( imgLeft.rows, imgLeft.cols, CV_16S );
Mat imgDisparity8U = Mat( imgRight.rows, imgRight.cols, CV_8UC1 );
int ndisparities = 16*5;
int SADWindowSize = 21;
StereoBM sbm( StereoBM::BASIC_PRESET,ndisparities,SADWindowSize );
sbm( imgLeft, imgRight, imgDisparity16S, CV_16S );
double minVal; double maxVal;
minMaxLoc( imgDisparity16S, &minVal, &maxVal );
printf("Min disp: %f Max value: %f \n", minVal, maxVal);
imgDisparity16S.convertTo( imgDisparity8U, CV_8UC1, 255/(maxVal - minVal));
namedWindow( windowDisparity, WINDOW_NORMAL );
imshow( windowDisparity, imgDisparity8U );
imshow( "left", imgLeft );
imshow( "right", imgRight );
imwrite("SBM_sample.png", imgDisparity16S);
waitKey(0);
return 0;
}
my problem is that I can't find the depth Z between object and camera

Maybe try to convert disparity to 3D points using cv::reprojectImageTo3D() or cv::perspectiveTransform() for sparse set of points.

Related

CascadeClassifier openCV

I wrote this program by C++ using OpenCV to detect pedestrians.xml file that I have. The program should read all of the input images and display blue rectangles on the output images where pedestrians are located. But the code is giving me errors. Is there anyone who can tell me why these errors come?
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/features2d/features2d.hpp>
#include<iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
using namespace cv;
void detectAndDisplay( Mat frame );
/** Global variables */
String pedestrians_name = "hogcascade_pedestrians.xml";
//CascadeClassifier pedestrians;
string window_name = "Capture - pedestrians detection";
RNG rng(12345);
/** #function main */
int main( int argc, const char** argv )
{
CvCapture* capture;
Mat frame;
//-- 1. Load the cascades
//if( !pedestrians.load( pedestrians_name ) ){ printf("--(!)Error loading\n"); return -1; };
Mat image = imread("ped1.jpg");
Mat image_keypoints;
cvtColor(image, image_keypoints, CV_BGR2GRAY);
return 0;
}
/** #function detectAndDisplay */
void detectAndDisplay( Mat frame )
{
std::vector<Rect> pedestrians;
Mat frame_gray;
cvtColor( frame, frame_gray, CV_BGR2GRAY );
equalizeHist( frame_gray, frame_gray );
//-- Detect faces
pedestrians.detectMultiScale( frame_gray, pedestrians, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) );
void CascadeClassifier::detectMultiScale(const Mat& image, vector<Rect>& objects, double scaleFactor=1.1, int minNeighbors=3, int flags=0, Size minSize=Size(), Size maxSize=Size());
for( int i = 0; i < pedestrians.size(); i++ )
{
Point center( pedestrians[i].x + pedestrians[i].width*0.5, pedestrians[i].y + pedestrians[i].height*0.5 );
ellipse( frame, center, Size( pedestrians[i].width*0.5, pedestrians[i].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 );
Mat faceROI = frame_gray( pedestrians[i] );
std::vector<Rect> eyes;
//-- In each face, detect eyes
/*eyes_cascade.detectMultiScale( faceROI, eyes, 1.1, 2, 0 |CV_HAAR_SCALE_IMAGE, Size(30, 30) );
for( size_t j = 0; j < eyes.size(); j++ )
{
Point center( faces[i].x + eyes[j].x + eyes[j].width*0.5, faces[i].y + eyes[j].y + eyes[j].height*0.5 );
int radius = cvRound( (eyes[j].width + eyes[j].height)*0.25 );
circle( frame, center, radius, Scalar( 255, 0, 0 ), 4, 8, 0 );
}*/
}
//-- Show what you got
imshow( window_name, frame );
}
these are the errors:
cascade.cpp: In function âvoid detectAndDisplay(cv::Mat)â:
cascade.cpp:46: error: âclass std::vector<cv::Rect_<int>, std::allocator<cv::Rect_<int> > >â has no member named âdetectMultiScaleâ
cascade.cpp:46: error: âCV_HAAR_SCALE_IMAGEâ was not declared in this scope
cascade.cpp:47: error: âCascadeClassifierâ has not been declared
cascade.cpp:47: error: invalid use of qualified-name â<declaration error>::detectMultiScaleâ
You need to add opencv_objdetect library. And include "opencv2/objdetect.hpp".
create a Cascade classifier object and load the xml file obj.load(xml file path)
First of all, in main() you never called detectAndDisplay() right? You need to call it if you want to execute it...
Second of all, you need to declare and load a cascade classifier in detectAndDisplay() before you use detectMultiScale.
CascadeClassifier pedestrians;
if( !pedestrians.load( pedestrians_name ) ){
printf("--(!)Error loading\n");
return;}
//.....
pedestrians.detectMultiScale( frame_gray, pedestrians, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) );

Displaying Multiple Images on Single window with OpenCV 3.0 and MSVS 12

i am new to opencv as well as to c++ and currently working on a program that requires me to display multiple images with opencv version 3.0 and visual studio 12. i am working on the following codes but it did not work. I would like to ask on how can i solve the problem.
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
//Image Reading
IplImage* img1 = cvLoadImage( "ball.jpg" );
IplImage* img2 = cvLoadImage( "ball.jpg" );
IplImage* img3 = cvLoadImage( "ball.jpg" );
IplImage* img4 = cvLoadImage( "ball.jpg" );
int dstWidth=img1->width+img1->width;
int dstHeight=img1->height+img1->height;
IplImage* dst=cvCreateImage(cvSize(dstWidth,dstHeight),IPL_DEPTH_8U,3);
// Copy first image to dst
cvSetImageROI(dst, cvRect(0, 0,img1->width,img1->height) );
cvCopy(img1,dst,NULL);
cvResetImageROI(dst);
// Copy second image to dst
cvSetImageROI(dst, cvRect(img2->width, 0,img2->width,img2->height) );
cvCopy(img2,dst,NULL);
cvResetImageROI(dst);
// Copy third image to dst
cvSetImageROI(dst, cvRect(0, img3->height,img3->width,img3->height) );
cvCopy(img3,dst,NULL);
cvResetImageROI(dst);
// Copy fourth image to dst
cvSetImageROI(dst, cvRect(img4->width, img4->height,img4->width,img4->height) );
cvCopy(img4,dst,NULL);
cvResetImageROI(dst);
//show all in a single window
cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
cvShowImage( "Example1", dst );
cvWaitKey(0);
}
Here's how you can do it with C++ API, if all images have the same size:
int main(int argc, char* argv[])
{
cv::Mat input1 = cv::imread("C:/StackOverflow/Input/Lenna.png");
cv::Mat input2 = cv::imread("C:/StackOverflow/Input/Lenna.png");
cv::Mat input3 = cv::imread("C:/StackOverflow/Input/Lenna.png");
cv::Mat input4 = cv::imread("C:/StackOverflow/Input/Lenna.png");
int width = 2*input1.cols; // width of 2 images next to each other
int height = 2*input1.rows; // height of 2 images over reach other
cv::Mat inputAll = cv::Mat(height, width, input1.type());
cv::Rect subImageROI = cv::Rect(0, 0, input1.cols, input1.rows);
// copy to subimage:
input1.copyTo(inputAll(subImageROI));
// move to 2nd image ROI position:
subImageROI.x = input1.cols;
input2.copyTo(inputAll(subImageROI));
subImageROI.x = 0;
subImageROI.y = input1.rows;
input3.copyTo(inputAll(subImageROI));
subImageROI.x = input1.cols;
subImageROI.y = input1.rows;
input4.copyTo(inputAll(subImageROI));
cv::imshow("input", inputAll);
cv::waitKey(0);
return 0;
}

error in implementation of dct in opencv

why the following errors occur when i try to implement dct in opencv?
Assertion failed (type == CV_32FC1 || type == CV_64FC1) in dct,
here is the code:
#include <cv.h>
#include "opencv2/imgproc/imgproc.hpp"
#include <highgui.h>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
Mat image,dimage(image);
image = imread( "lena.jpg", 1 );
if( !image.data )
{
printf( "No image data \n" );
return -1;
}
namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
imshow( "Display Image", image );
dimage=Mat::zeros(image.rows,image.cols,CV_32F);
dct(image, dimage, DCT_INVERSE == 0 );
namedWindow( "DCT Image", CV_WINDOW_AUTOSIZE );
imshow( "DCT image", dimage );
waitKey(0);
return 0;
}
you have to convert your image from uchar to float first (and maybe back to uchar later):
// also please use the c++ headers, not the old c-ones !
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
Mat image = imread( "lena.jpg", 0 ); // grayscale
Mat fimage;
image.convertTo(fimage, CV_32F, 1.0/255); // also scale to [0..1] range (not mandatory)
// you're lucky with lena (512x512), for odd sizes, you have to
// pad it to pow2 size, or use dft() instead:
Mat dimage;
dct( fimage, dimage );
// process dimage,
// then same way back:
dct( dimage, dimage, DCT_INVERSE );
dimage.convertTo(image, CV_8U); // maybe scale back to [0..255] range (depending on your processing)
imshow("result",image);
waitKey();

opencv stereo vision depth map, code does not work

I am studying on stereo vision depth map and I am using the opencv library.I wrote a program to obtain depth map. But when program was run I obtained an empty depth map frame.can anybody help me please, what is wrong ? code are shown in below;
#include <opencv/highgui.h>
#include <opencv/cv.h>
#include <stdio.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <math.h>
#include <opencv2/calib3d/calib3d.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/contrib/contrib.hpp>
int main()
{
IplImage* img1 = cvLoadImage("/home/sezen/Masaüstü/imR.png");
IplImage* img2 = cvLoadImage("/home/sezen/Masaüstü/imL.png");
IplImage *rimage = cvCreateImage(
cvSize( img1->width, img1->height ), IPL_DEPTH_8U, 1 );
cvCvtColor( img1, rimage, CV_RGB2GRAY );
IplImage *limage = cvCreateImage(
cvSize( img2->width, img2->height ), IPL_DEPTH_8U, 1 );
cvCvtColor( img2, limage, CV_RGB2GRAY );
cvNamedWindow( "Right", CV_WINDOW_AUTOSIZE );
cvShowImage( "Right", rimage );
cvNamedWindow( "Left", CV_WINDOW_AUTOSIZE );
cvShowImage("Left", limage);
CvMat *matr = cvCreateMat(rimage->height,rimage->width,CV_8UC1 );
CvMat *matl = cvCreateMat(limage->height,limage->width,CV_8UC1 );
CvMat* disp = cvCreateMat(rimage->height,rimage->width,CV_16S);
CvMat* vdisp = cvCreateMat(rimage->height,rimage->width,CV_16S);
cvConvert( rimage, matr );
cvConvert( limage, matl );
CvStereoBMState *BMState = cvCreateStereoBMState();
assert(BMState != 0);
BMState->preFilterSize=21;
BMState->preFilterCap=31;
BMState->SADWindowSize=21;
BMState->minDisparity=0;
BMState->numberOfDisparities=128;
BMState->textureThreshold=10;
BMState->uniquenessRatio=15;
cvFindStereoCorrespondenceBM( matr, matl, disp, BMState);
cvNormalize(disp, vdisp, 0, 255, CV_MINMAX);
cvShowImage("depthmap", vdisp);
cvWaitKey(0);
return 0;
}
Here's a code for disparity map using C++ API. Final image that you normalize should be of type CV_8UC1.
Mat img1, img2, g1, g2;
Mat disp, disp8;
img1 = imread("leftImage.jpg");
img2 = imread("rightImage.jpg");
cvtColor(img1, g1, CV_BGR2GRAY);
cvtColor(img2, g2, CV_BGR2GRAY);
StereoBM sbm;
sbm.state->SADWindowSize = 9;
sbm.state->numberOfDisparities = 112;
sbm.state->preFilterSize = 5;
sbm.state->preFilterCap = 61;
sbm.state->minDisparity = -39;
sbm.state->textureThreshold = 507;
sbm.state->uniquenessRatio = 0;
sbm.state->speckleWindowSize = 0;
sbm.state->speckleRange = 8;
sbm.state->disp12MaxDiff = 1;
sbm(g1, g2, disp);
normalize(disp, disp8, 0, 255, CV_MINMAX, CV_8U);
imshow("left", img1);
imshow("right", img2);
imshow("disp", disp8);
I can only add that structure of OpenCV namespaces and classes changes every year.
I placed below working source code for OpenCV 3.4.0
#include <Windows.h>
#include <Vfw.h>
#include <string>
#include <iostream>
#include "opencv2\core\core.hpp"
#include "opencv2\imgproc\imgproc.hpp"
#include "opencv2\imgcodecs\imgcodecs.hpp"
#include "opencv2\highgui\highgui.hpp"
#include "opencv2\calib3d\calib3d.hpp"
using namespace std;
using namespace cv;
int _tmain(int argc, _TCHAR* argv[])
{
Mat im_left=imread("right.png");
Mat im_right=imread("left.png");
cv::Size imagesize = im_left.size();
cv::Mat disparity_left=cv::Mat(imagesize.height,imagesize.width,CV_16S);
cv::Mat disparity_right=cv::Mat(imagesize.height,imagesize.width,CV_16S);
cv::Mat g1,g2,disp,disp8;
cv::cvtColor(im_left,g1,cv::COLOR_BGR2GRAY);
cv::cvtColor(im_right,g2,cv::COLOR_BGR2GRAY);
cv::Ptr<cv::StereoBM> sbm = cv::StereoBM::create(0,21);
sbm->setDisp12MaxDiff(1);
sbm->setSpeckleRange(8);
sbm->setSpeckleWindowSize(9);
sbm->setUniquenessRatio(0);
sbm->setTextureThreshold(507);
sbm->setMinDisparity(-39);
sbm->setPreFilterCap(61);
sbm->setPreFilterSize(5);
sbm->compute(g1,g2,disparity_left);
normalize(disparity_left, disp8, 0, 255, CV_MINMAX, CV_8U);
cv::namedWindow("Left",CV_WINDOW_FREERATIO);
cv::imshow("Left", im_left);
cv::namedWindow("Right",CV_WINDOW_FREERATIO);
cv::imshow("Right", im_right);
cv::namedWindow("Depth map",CV_WINDOW_FREERATIO);
cv::imshow("Depth map", disp8);
cv::waitKey(0);
return 0;
}
For me it worked slightly different with the init of the stereoBM object
Ptr<StereoBM> sbm = cv::StereoBM::create(16, 5);
sbm->setDisp12MaxDiff(1);
sbm->setSpeckleRange(8);
sbm->setSpeckleWindowSize(0);
sbm->setUniquenessRatio(0);
sbm->setTextureThreshold(507);
sbm->setMinDisparity(-39);
sbm->setPreFilterCap(61);
sbm->setPreFilterSize(5);
sbm->compute(src1, src2, disp);
I edited the code to my needs, I added the camera one and two, and reading from them.
Then, made the Depth map. Thanks hope its helpful.
#include <string>
#include <iostream>
#include <opencv2/opencv.hpp>
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/imgcodecs/imgcodecs.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/calib3d/calib3d.hpp"
using namespace std;
using namespace cv;
int main()
{
VideoCapture leftCam(0); //lets say 0 is left, 1 is right
if (leftCam.isOpened() == false){cout << "error: Webcam connect unsuccessful\n"; return(0); }
VideoCapture rightCam(1); //lets say 0 is left, 1 is right
if (rightCam.isOpened() == false){cout << "error: Webcam connect unsuccessful\n"; return(0); }
Mat left, right;
Mat leftClone, rightClone;
char charCheckForEscKey = 0;
while ( charCheckForEscKey != 27 && leftCam.isOpened() )
{
leftCam.read(left);
if (left.empty()){cout << "No frame to read" << endl; break;}
leftClone = left.clone(); //copy from the left camera
imwrite("left.png", leftClone); // write it to screenshot.png in this directory
rightCam.read(right);
if (right.empty()){cout << "No frame to read" << endl; break;}
rightClone = right.clone(); //copy from the left camera
imwrite("right.png", rightClone); // write it to screenshot.png in this directory
Mat im_left = imread("left.png"); //left cam picture
Mat im_right = imread("right.png"); // right cam picture
Size imagesize = im_left.size();
Mat disparity_left= Mat(imagesize.height,imagesize.width,CV_16S);
Mat disparity_right=Mat(imagesize.height,imagesize.width,CV_16S);
Mat g1,g2,disp,disp8;
cvtColor(im_left,g1, COLOR_BGR2GRAY);
cvtColor(im_right,g2, COLOR_BGR2GRAY);
Ptr<cv::StereoBM> sbm = StereoBM::create(0,21);
sbm->setDisp12MaxDiff(1);
sbm->setSpeckleRange(8);
sbm->setSpeckleWindowSize(9);
sbm->setUniquenessRatio(0);
sbm->setTextureThreshold(507);
sbm->setMinDisparity(-39);
sbm->setPreFilterCap(61);
sbm->setPreFilterSize(5);
sbm->compute(g1,g2,disparity_left);
normalize(disparity_left, disp8, 0, 255, NORM_MINMAX, CV_8U);
namedWindow("Left", WINDOW_AUTOSIZE);
imshow("Left", im_left);
namedWindow("Right", WINDOW_AUTOSIZE);
imshow("Right", im_right);
namedWindow("Depth map", WINDOW_AUTOSIZE);
imshow("Depth map", disp8);
namedWindow("Left Cloned", WINDOW_FREERATIO);
imshow("Left Cloned", leftClone); // left is the left pic taken from camera 0
charCheckForEscKey = waitKey(1);
}
return(0);
}
#include <opencv2/opencv.hpp>
#include <opencv2/highgui.hpp>
#include<opencv2/calib3d.hpp>
int main()
{
cv::Mat leftimg =cv::imread("leftimage.jpg");
cv::Mat rightimg = cv::imread("rightimage.jpg");
cv::Mat disparity_left=cv::Mat(leftimg.size(),leftimg.type());
cv::Mat disparity_right=cv::Mat(rightimg.size(),rightimg .type());
cv::Mat g1,g2,disp,disp8;
cv::cvtColor(leftimg,g1,cv::COLOR_BGR2GRAY);
cv::cvtColor(rightimg,g2,cv::COLOR_BGR2GRAY);
cv::Ptr<cv::StereoBM> sbm = cv::createStereoBM(16,21);
sbm->setDisp12MaxDiff(1);
sbm->setSpeckleRange(8);
sbm->setSpeckleWindowSize(9);
sbm->setUniquenessRatio(0);
sbm->setTextureThreshold(507);
sbm->setMinDisparity(-39);
sbm->setPreFilterCap(61);
sbm->setPreFilterSize(5);
sbm->compute(g1,g2,disparity_left);
normalize(disparity_left, disp8, 0, 255, CV_MINMAX, CV_8U);
}

Automatic Image Stitching from video with opencv

Hy, i have error when i stitch frame from video,
here's my code
#include <stdio.h>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/nonfree.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/imgproc/imgproc.hpp"
using namespace std;
using namespace cv;
Mat Stitching(Mat image1,Mat image2){
Mat gray_image1;
Mat gray_image2;
// Convert to Grayscale
cvtColor( image1, gray_image1, CV_RGB2GRAY );
cvtColor( image2, gray_image2, CV_RGB2GRAY );
//-- Step 1: Detect the keypoints using SURF Detector
int minHessian = 10;
SurfFeatureDetector detector( minHessian );
std::vector< KeyPoint > keypoints_object, keypoints_scene;
detector.detect( gray_image1, keypoints_object );
detector.detect( gray_image2, keypoints_scene );
//-- Step 2: Calculate descriptors (feature vectors)
SurfDescriptorExtractor extractor;
Mat descriptors_object, descriptors_scene;
extractor.compute( gray_image1, keypoints_object, descriptors_object );
extractor.compute( gray_image2, keypoints_scene, descriptors_scene );
//-- Step 3: Matching descriptor vectors using FLANN matcher
FlannBasedMatcher matcher;
std::vector< DMatch > matches;
matcher.match( descriptors_object, descriptors_scene, matches );
double max_dist = 0; double min_dist = 100;
//-- Quick calculation of max and min distances between keypoints
for( int i = 0; i < descriptors_object.rows; i++ )
{ double dist = matches[i].distance;
if( dist < min_dist ) min_dist = dist;
if( dist > max_dist ) max_dist = dist;
}
printf("-- Max dist : %f \n", max_dist );
printf("-- Min dist : %f \n", min_dist );
//-- Use only "good" matches (i.e. whose distance is less than 3*min_dist )
std::vector< DMatch > good_matches;
for( int i = 0; i < descriptors_object.rows; i++ )
{ if( matches[i].distance < 3*min_dist )
{ good_matches.push_back( matches[i]); }
}
std::vector< Point2f > obj;
std::vector< Point2f > scene;
for( int i = 0; i < good_matches.size(); i++ )
{
//-- Get the keypoints from the good matches
obj.push_back( keypoints_object[ good_matches[i].queryIdx ].pt );
scene.push_back( keypoints_scene[ good_matches[i].trainIdx ].pt );
}
// Find the Homography Matrix
Mat H = findHomography( obj, scene, CV_RANSAC );
// Use the Homography Matrix to warp the images
cv::Mat result;
warpPerspective(image1,result,H,cv::Size(800,600));
cv::Mat half(result,cv::Rect(0,0,image2.cols,image2.rows));
image2.copyTo(half);
//imshow( "Result", result );
return result;
}
/** #function main */
int main( int argc, char** argv )
{
// Load the images
//Mat image1= imread( "E:\\Tugas Akhir\\image\\city2.jpg" );
//Mat image2= imread( "E:\\Tugas Akhir\\image\\city1.jpg" );
char *fileName = "E:\\Tugas Akhir\\Video Master\\indv_img_3a.avi";
/* Create a window */
cvNamedWindow("Stitching", CV_WINDOW_AUTOSIZE);
/* capture frame from video file */
CvCapture* capture = cvCreateFileCapture(fileName);
/* Create IplImage to point to each frame */
IplImage* frame;
IplImage before_frame;
Mat image1;
Mat image2;
cv::Mat result;
/* Loop until frame ended or ESC is pressed */
int loop=0;
//imshow( "Result", Stitching(image1,image2));
while(1) {
frame = cvQueryFrame(capture);
if(loop>0){
if(!frame) break;
image2=Mat(frame, false);
result=Stitching(image1,image2);
before_frame=result;
frame=&before_frame;
image1=result;
image2.release();
//imshow("Stitching",frame);
cvShowImage("Stitching",frame);
//break;
}else if(loop==0){
//Mat aimage1(frame);
image1=Mat(frame, false);
}
loop++;
char c = cvWaitKey(33);
if(c==27) break;
}
cvReleaseCapture(&capture);
/* delete window */
// cvDestroyWindow("Stitching");
// return EXIT_SUCCESS;
waitKey(0);
return 0;
}
if i load from image file, it works, image stitched, but when i try to stitch image from every video frame , it shows error
First-chance exception at 0x000007f886dd64a8 in matchingHomography.exe: Microsoft C++ exception: cv::Exception at memory location 0x0080e3b0..
Unhandled exception at 0x000007f886dd64a8 in matchingHomography.exe: Microsoft C++ exception: cv::Exception at memory location 0x0080e3b0..
line error
Mat H = findHomography( obj, scene, CV_RANSAC );
what's the error mean? and how to solve it
thanks
First off, you seem to be mixing C and C++ interfaces of OpenCV (OpenCV VideoCapture doc). For better readability stick to one of them (Since you are using C++ just stick to using C++ functions).
Since loading from image works, but Video doesn't, your video loading is probably the problem.
Try using cv::imshow("testWindow", frame) to show the frame loaded from video. Most likely there was no frame loaded.
One possible cause is that the video file is encoded in a format not supported by OpenCV. To check you can also run grab() and then retrieve(). The grab function will return if it was successful or not. Try grabbing a couple of frames, if all of them fail you probably don't have the necessary codec to decode this video.