Ask Your Question

Salman's profile - activity

2015-08-26 05:27:29 -0600 asked a question Keypoints and Descriptors in SURF

I'm new to openCV i m currently working on stitching algorithm.

In step1 the key points are detected using SURF detector, 1)which key points are detected by SURF? 2) the argument uses "Hessian",assigned a value 400 ("taken from openCV tutorial"). What is the role of this argument? 3) In the next step, the key points from step1 are used to computer "descriptors"? what are these descriptors?

Thanks for your help.!

//-- Step 1: Detect the keypoints using SURF Detector int minHessian = 400;

SurfFeatureDetector detector(minHessian);

std::vector<KeyPoint> keypoints_1, keypoints_2;

detector.detect(image1, keypoints_1);
detector.detect(image2, keypoints_2);

//-- Step 2: Calculate descriptors 
SurfDescriptorExtractor extractor;

Mat descriptors_1, descriptors_2;

extractor.compute(image1, keypoints_1, descriptors_1);
extractor.compute(image2, keypoints_2, descriptors_2);
2015-08-26 03:09:36 -0600 received badge  Scholar (source)
2015-08-26 03:09:31 -0600 received badge  Supporter (source)
2015-08-21 13:53:40 -0600 commented answer accessing cameras- abort() call

@pklab: so how would i add the time delay in between? sleep() method isn't recognized by the editor.

2015-08-21 13:07:12 -0600 commented answer accessing cameras- abort() call

i'm new to OpenCV one thing i just don't understand, one code worked fine one day and the very next day the same code for same cameras gives such errors lol how is that possible.

2015-08-21 12:50:03 -0600 commented answer accessing cameras- abort() call

@pklab: its still not done :( this is what I've made in accordance with your suggestion, the problem is still the same, either of the 2 cams captures the frame. I want to take picture from both the webcams simultaneously :(

#include "opencv2/opencv.hpp"
using namespace cv;

int main(int argc, char** argv)
{

    VideoCapture cap(2);

    if (!cap.isOpened())
    {
        std::cout << " --(!) Error reading image from Device 2 " << std::endl;
        return -1;
    }
    Mat frame;
    cap >> frame;

    if (!frame.empty())
    imshow("Frame of Device 1", frame);

    VideoCapture cap2(0);

    if (!cap2.isOpened())
    {
        std::cout << " --(!) Error reading image from Device 0 " << std::endl;
        return -1;
    }
    Mat frame2;
    cap2 >> frame2;

    if (!frame2.empty())
        imshow("Frame of Device 0", frame2)

    waitKey();
    return;
}
2015-08-21 11:16:50 -0600 commented answer accessing cameras- abort() call

@pklab the error is somewhere else... its still not working ... for a test, i just tried to run another fine and working code while only laptop builtin camera was working, this code (written below) worked. The moment i plugged in my 1st webcam (now 1 webcam and builtin cam is connected) this code also give a call to abort() .. the same error for previous code.. closing VS13 running code again , makes everything correct again...so its not the code, the error is some where else?? am i right ? 2nd Code:

int main(int, char**)

{ VideoCa1pture cap(0); if (!cap.isOpened()) { std::cerr << "ERROR: Could not open camera" << std::endl; } namedWindow("video", 1); for (;;) { Mat frame; cap >> frame; if (waitKey(30) >= 0) break; }

2015-08-21 11:01:06 -0600 commented answer accessing cameras- abort() call

and what is the logic of using AND around the empty(), why not OR? what difference does it make ?

2015-08-21 11:00:44 -0600 commented answer accessing cameras- abort() call

@pklab with the same logic (without even a single change) it worked precised but now it gives an error :/... Anyhow according to your suggestion I've altered the code, surprisingly the error is removed :) but ... only frame of device 0 is captured, nothing is taken from Device 1 :/ :(

2015-08-21 10:30:25 -0600 asked a question accessing cameras- abort() call

Hi, I've this simple code which worked fine for my 2 U.S.B webcams, but now for some strange reasons it sometimes stuck and it shows Runtime library error "R6010 abort() has been called". Detaching one of the camera, running the code again makes everything fine and sometimes just closing VS13 repairs it. I find it really absurd pls give any solution.

#include "opencv2/opencv.hpp"

using namespace cv;

int main(int argc, char** argv)
{
VideoCapture cap(1);
VideoCapture cap2(0);

if (!cap.open(1) || !cap2.open(0))
{
    std::cout << " --(!) Error reading images " << std::endl;
    return -1;
}

Mat frame;
Mat frame2;

cap >> frame;
cap2 >> frame2;

if (!frame.empty() || !frame2.empty())
{
    imshow("Frame of Device 0", frame);
    imshow("Frame of Device 1", frame2);
    //imwrite("imageold.jpeg", frame);
    //imwrite("imagenew.jpeg", frame2);
}
waitKey();
return 0;

}

2015-08-20 00:42:25 -0600 asked a question error reading images from command line in VS13

In Vs13 , i'm giving cmd line argument in this way: Solution Explorer Properties -> Debugging -> Command Argument -> "D:/images/image1.jpeg" "D:/images/image2.jpeg"

On running this code, it displays the error: Error reading original images . Pls fix the code

include <stdio.h>

include <iostream>

using namespace cv;

void readme();

/* @function main */ int main(int argc, char* argv) { if (argc != 3) { readme(); return -1; }

// Load the images
Mat image1 = imread(argv[2]);
Mat image2 = imread(argv[1]);
if (!image1.data || !image2.data)
{
    std::cout << " --(!) Error reading original images " << std::endl; return -1;
}

Mat gray_image1;
Mat gray_image2;


// Convert to Grayscale
cvtColor(image1, gray_image1, CV_RGB2GRAY);
cvtColor(image2, gray_image2, CV_RGB2GRAY);

imshow("image1", image2);
imshow("image2", image1);

if (!gray_image1.data || !gray_image2.data)
{
    std::cout << " --(!) Error reading gray images " << std::endl; return -1;
}

waitKey(0);
return 0;

}

/** @function readme */ void readme() { std::cout << " Usage: Panorama < img1 > < img2 >" << std::endl; }

2015-08-19 11:43:55 -0600 commented question imread, command line arguments in VS13

@LBerger: these errors doesn't matter unless at least single image is read, which is not done :/ and i'm confused why is that.. :(

2015-08-19 08:57:30 -0600 commented question imread, command line arguments in VS13

sorry friend @LBerger you pointed out the right mistake but unfortunately the code even doesn't reach there. It gives "Error The image can't be loaded" as i mentioned i'm unable to load my images by command line arguments.

2015-08-19 06:31:06 -0600 asked a question imread, command line arguments in VS13

I'm trying to run this code in VS13 that uses command line argument I'm following this method but its nt working.

Solution Explorer Properties Debugging Command Arguments "D:/Images/image1.jpeg" "D:/Images/image2.jpeg"

Code:

#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <stdio.h>
#include <iostream>


using namespace std;
using namespace cv;

int main(int argc, char* argv[])
{

Mat img;
Mat img2;

img = imread(argv[1], CV_LOAD_IMAGE_COLOR);
img2 = imread(argv[2], CV_LOAD_IMAGE_COLOR);

if (img.empty() || img2.empty)
{
    cout << "Error: Image cannot be loaded!" << endl;
    system("pause");
    return -1;
}

namedWindow("Image", CV_WINDOW_AUTOSIZE);
imshow("Image", img);
namedWindow("Imag2", CV_WINDOW_AUTOSIZE);
imshow("Image2", img2);

waitKey(0);
return 0;

}

2015-08-19 06:21:07 -0600 commented question assertion failed

you were right, images were not uploaded. I've restored the original version of the code that passes command line argument. However this doesn't work too :/ I'm using VC13 and i've given the arguments to properties of solution explorer -> debugging -> command argument -> "C:/image1.jpeg" "C:/image2.jpeg"

using namespace std; using namespace cv;

int main(int argc, char* argv[]) { Mat img;

img = imread(argv[1], CV_LOAD_IMAGE_COLOR);

if (img.empty())
{
    cout << "Error: Image cannot be loaded!" << endl;
    system("pause");
    return -1;
}

namedWindow("Image", CV_WINDOW_AUTOSIZE);
imshow("Image", img);

waitKey(0);
destroyWindow("Image");

return 0;
2015-08-19 05:28:26 -0600 received badge  Editor (source)
2015-08-19 05:27:56 -0600 asked a question stitcher class functionality

Hi, i'm looking for working steps and explanation of stitcher class. how createdefault() , stitch() , status() and other methods actually work. I studied some basic explanation of stitching pipeline and want to explore it more. I'm a beginner level programmer i want to have rudiment knowledge of openCv. Thanks

2015-08-18 13:44:33 -0600 asked a question assertion failed

on running this code an assertion failed error occurred on cmd line window

OPENCV Error : Assertion Failed <scn =="3" ||="" scn="4"> in cv::cvtColor,file:C:(address)

#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 cv;

/** @function main */
int main()
{


    // Load the images
    Mat image1 = imread("scene11.jpeg");
    Mat image2 = imread("scene21.jpeg");
    Mat gray_image1;
    Mat gray_image2;
    // Convert to Grayscale
    cvtColor(image1, gray_image1, CV_RGB2GRAY);
    cvtColor(image2, gray_image2, CV_RGB2GRAY);

    imshow("image1", image2);
    imshow("image2", image1);

    if (!gray_image1.data || !gray_image2.data)
    {
        std::cout << " --(!) Error reading images " << std::endl; return -1;
    }

    //-- Step 1: Detect the keypoints using SURF Detector
    int minHessian = 400;

    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 (size_t 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(image1.cols + image2.cols, image1.rows));
    cv::Mat half(result, cv::Rect(0, 0, image2.cols, image2.rows));
    image2.copyTo(half);
    imshow("Result", result);

    waitKey(0);
    return 0;
}
2015-08-16 10:14:53 -0600 commented question capturing image using more than one camera

@theodore The following code provides me snapshots , but I don't want the first frame. I want to put some delay between the start of device and grabbing a frame so that any blurred frame or low quality frame may be discarded. For this my remedy was to take multiple pictures and waste the initial frames and that is what i made but this din't work. What you guys would suggest ?

#include "opencv2/opencv.hpp"

using namespace cv;

int main(int argc, char** argv)
{

VideoCapture cap(0);
VideoCapture cap2(1);

if (!cap.open(0) || !cap2.open(1))
    return 0;


Mat frame;
Mat frame2;

cap >> frame;
cap2 >> frame2;

if (!frame.empty() || !frame2.empty())
{
    imshow("Frame of Device 0", frame);
    imshow("Frame of Device 1", frame2);

}
waitKey();
return 0;

}

2015-08-16 08:07:41 -0600 asked a question capturing image using more than one camera

I want to capture image from 2 cameras connected to my laptop. when i run this code, it is compiled fine but it shows nothing. Pls fix this issue.

#include "opencv2/opencv.hpp"

using namespace cv;

int main(int argc, char** argv)
{
    VideoCapture cap(0);
    VideoCapture cap2(1);

    if (!cap.open(0)||!cap2.open(1))
        return 0;

    Mat frame[3]; 
    Mat frame2[3];

    for (int i = 0; i < 2; i++)
    {
        cap >> frame[i];
        cap2 >> frame2[i];
        i++

        if (!frame[2].empty() || !frame2[2].empty())
        {
            imshow(format("Frame of Device 0"), frame[2]);
            imshow(format("Frame of Device 1"), frame[2]);
        }

    }

    waitKey();
    return 0;
}