Ask Your Question

tomriddle's profile - activity

2015-04-10 05:16:23 -0600 asked a question Initial camera orientations from camera calibration are totally wrong

Hi,

I'm using OpenCV's camera calibration function, I have 34 images of the checkerboard on a turntable, taken from a static camera. The camera position from the initial tvec is approximately correct, however the rvec is totally wrong. I ploted the orientation in matlab to indicate the problem.

wrongOrientation.jpg

The formula I used should be correct like,this.

My question is why these orientations are wrong ? is this normal for the calibration algorithm? Matlab uses Z as the up axis, could this be my visualization code problem ?

Thanks.

Edit: Crosspost: http://stackoverflow.com/questions/29...

2014-11-21 18:59:07 -0600 received badge  Student (source)
2013-10-28 20:12:31 -0600 asked a question imwrite doesn't output correct PBM file format in the header.

I need opencv to write PBM file which the header should be 'P4' described in this web site.

However I checked OpenCV 2.4.6.1's source code grfmt_pxm.cpp

sprintf( buffer, "P%c\n%d %d\n%d\n",
             '2' + (channels > 1 ? 1 : 0) + (isBinary ? 3 : 0),
             width, height, (1 << depth) - 1 );

So I can see it can never be '4' after 'P'. So I'm asking here whether OpenCV support PBM file format, how should I write the file.

Currently I write my file like this,

Mat outputmask(mask.size(), CV_8UC1, Scalar::all(1)) ;
outputmask = outputmask-mask ;
imwrite( pathAndName + "_mask" + ".pbm", outputmask , write_params );

outputmask is all 0 or 1, but it's CV_8UC1 datatype, since OpenCV doesn't support binary. write_params is a vector only contains CV_IMWRITE_PXM_BINARY. This block outputs 'P5' in the PBM file's header which is wrong, because 'P5' is PGM file's header.

2013-09-23 02:14:27 -0600 received badge  Self-Learner (source)
2013-09-22 22:58:54 -0600 answered a question How to convert cv::Mat to std::string and hash it using MD5 ?

Worked it out.

#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <functional>
#include <openssl/md5.h>

using namespace std;
using namespace cv;

static void help()
{
}

char *str2md5(const char *str, int length) {
    int n;
    MD5_CTX c;
    unsigned char digest[16];
    char *out = (char*)malloc(33);

    MD5_Init(&c);

    while (length > 0) {
        if (length > 512) {
            MD5_Update(&c, str, 512);
        } else {
            MD5_Update(&c, str, length);
        }
        length -= 512;
        str += 512;
    }

    MD5_Final(digest, &c);

    for (n = 0; n < 16; ++n) {
        snprintf(&(out[n*2]), 16*2, "%02x", (unsigned int)digest[n]);
    }

    return out;
}


int main(int argc, const char** argv)
{
    help();

    if (argc != 2)
    {
        return EXIT_FAILURE ;
    }

    string inputfile = argv[1] ;

    Mat src = imread (inputfile, -1) ;

    if (src.empty())
    {
        return EXIT_FAILURE ;
    }



    cout << str2md5((char*)src.data, (int)src.step[0] * src.rows) << " " << inputfile << endl ;




    return 0;
}
2013-09-22 22:57:05 -0600 received badge  Editor (source)
2013-09-22 22:55:32 -0600 answered a question How to convert cv::Mat to std::string?

I worked out a solution like this.

src = imread("yourfile", -1) ;
str2md5((char*)src.data, (int)src.step[0] * src.rows)

(char*)src.data will cast your cv::Mat into char* type. So to construct a string you have to use string mat2str((char*)src.data, src.step[0] * src.rows) . You have to explicitly type the size of the string because there might be '\0' that breaks the string constructor recognize full length char*.

2013-09-22 18:56:57 -0600 commented question How to convert cv::Mat to std::string and hash it using MD5 ?

@berak, thanks so much, I didn't realize it. But I am still not sure if I'm doing it right to hash the cv::Mat. I got another example here . FileStorage fs (".xml", FileStorage::WRITE + FileStorage::MEMORY) ; fs <<"data"<< src ; string cvinternal = fs.releaseAndGetString() ; //cout << cvinternal.length() << endl ; cout << str2md5(cvinternal.c_str(), cvinternal.length()) << endl ;

How do you think use this to hash ?

2013-09-20 02:55:56 -0600 asked a question How to convert cv::Mat to std::string and hash it using MD5 ?

I need to find the repeated images (exact same, this is not a image similarity problem) by hashing. So I tried something like this, but this seems not right.

Mat src = imread (inputfile, -1) ;

char* rawPtr = new char[src.step[0] * src.rows] ;
memcpy(rawPtr, (char*)src.data, src.step[0] * src.rows) ; // is this all the data ??
string rawdata(rawPtr) ;

cout << str2md5(rawPtr, strlen(rawPtr)) << endl ;

My file is CV_16UC3, 1624 by 1236 , 3 channels, src.step[0] * src.rows is the bytes number of the whole image 12043584 bytes, however strlen(rawPtr) returns 5739852 chars, and these don't match.

So the md5 value I got is not right. I would like to know how to efficiently and correctly convert cv::Mat data into a string.