Ask Your Question

stereomatching's profile - activity

2020-11-13 03:43:29 -0600 received badge  Nice Question (source)
2019-05-10 12:44:33 -0600 received badge  Good Answer (source)
2018-10-24 02:26:17 -0600 received badge  Famous Question (source)
2018-09-13 15:35:19 -0600 received badge  Notable Question (source)
2018-06-15 08:48:17 -0600 received badge  Nice Answer (source)
2017-10-22 13:02:44 -0600 received badge  Nice Question (source)
2017-08-10 07:09:25 -0600 received badge  Famous Question (source)
2017-08-07 04:52:58 -0600 received badge  Famous Question (source)
2017-04-01 16:45:24 -0600 received badge  Famous Question (source)
2017-03-17 04:28:21 -0600 received badge  Notable Question (source)
2017-02-06 07:27:26 -0600 received badge  Popular Question (source)
2016-07-05 06:17:55 -0600 received badge  Enthusiast
2016-07-04 04:12:18 -0600 received badge  Nice Answer (source)
2016-07-04 03:25:01 -0600 answered a question mapping 2 document

I would use binary threshold, morphology and contours to solve this problem.

Step 1 : get the copy with signature

cv::Mat const map_01 = cv::imread("map01.jpg");

image description

Step 2 : blur the image and convert it to binary image

cv::Mat binarize;
cv::cvtColor(map_01, binarize, CV_BGR2GRAY);
cv::GaussianBlur(map_01, map_01, {5,5}, 3,3);
cv::threshold(binarize, binarize, 0, 255,
cv::THRESH_BINARY_INV | cv::THRESH_OTSU);

Step 3 : Use morphology to remove small blobs and make text blobs more obvious

auto mrect = cv::getStructuringElement(cv::MORPH_RECT, {3,3});
cv::erode(binarize, binarize, mrect);
mrect = cv::getStructuringElement(cv::MORPH_RECT, {7,5});
cv::morphologyEx(binarize, binarize, cv::MORPH_DILATE, mrect, {-1,-1}, 7);

Step 4 : find contours and remove those with invalid aspect ratio

std::vector<std::vector<cv::Point>> contours;
cv::findContours(binarize.clone(), contours, CV_RETR_EXTERNAL,
                 CV_CHAIN_APPROX_SIMPLE);
auto rit = std::remove_if(std::begin(contours), std::end(contours),
               [](auto const &ct)
{
    auto const rect = cv::boundingRect(ct);
    return rect.height > rect.width;
});
contours.erase(rit, std::end(contours));

Step 5 : Find the data of each rectangle

for(auto const &ct : contours){
    //get the information of each rect
    cv::Mat temp = map_01.clone();
    std::cout<<cv::boundingRect(ct)<<std::endl;
    cv::rectangle(temp, cv::boundingRect(ct), {255,0,0});
    cv::imshow("temp", temp);
    cv::waitKey();
    cv::destroyAllWindows();       
}

The bounding rects found by this solution are

image description

Step 6 : Extract text location according to the location and size of the bounding rects, this step is quite tedious.

Not a very good one, I believe there exist better solution, like find the difference between two images.

Source codes locate at github.

Edit : If the format and size of the are always the same, you can predefined the bounding rect of text candidates, extract the roi from predefined bounding rect, detect the binary value of those roi to find out the regions filled or not.

2016-07-03 13:50:28 -0600 commented question mapping 2 document

Not quite clear what do you want to do. Do you mean you want to teach the computer know how to read the words(OCR)?

2016-07-03 13:49:58 -0600 answered a question mapping 2 document

Not quite clear what do you want to do. Do you mean you want to teach the computer know how to read the words(OCR)?

2016-07-02 22:46:24 -0600 received badge  Necromancer (source)
2016-07-02 21:46:14 -0600 answered a question Image hashing implantation?

I have the same problem as Cory recently, to solve this problem once and for all, I develop an img_hash module for open_contrib, here is the pull request. img_hash module port the image hash algorithms of PHash library and implement some algorithms do not exist in the PHash library, this include color moment hash which provide good resistance to rotation attack(-90 to 90 degree).

The ReadMe of img_hash module should give you enough information of how to use and install the module, if you need more info, please ask me from the forum, or send the question to my [email protected]

This module is very easy to use, unlike PHash library, the api are consistent and do not force you to handle the resource by yourself.

#include <opencv2/core.hpp>
#include <opencv2/core/ocl.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/img_hash.hpp>
#include <opencv2/imgproc.hpp>

void computeHash(cv::Ptr<cv::img_hash::ImgHashBase> algo)
{
    cv::Mat const input = cv::imread("lena.png");
    cv::Mat const target = cv::imread("lena_blur.png");

    cv::Mat inHash; //hash of input image
    cv::Mat targetHash; //hash of target image

    //comupte hash of input and target
    algo->compute(input, inHash);
    algo->compute(target, targetHash);
    //Compare the similarity of inHash and targetHash
    //recommended thresholds are written in the header files
    //of every classes
    double const mismatch = algo->compare(inHash, targetHash);
    std::cout<<mismatch<<std::endl;
}

int main()
{
    //disable opencl acceleration may(or may not) boost up speed of img_hash
    cv::ocl::setUseOpenCL(false);

    computeHash(img_hash::AverageHash::create());
    computeHash(img_hash::PHash::create());
    computeHash(img_hash::MarrHildrethHash::create());
    computeHash(img_hash::RadialVarianceHash::create());
    //BlockMeanHash support mode 0 and mode 1, they associate to
    //mode 1 and mode 2 of PHash library
    computeHash(img_hash::BlockMeanHash::create(0));
    computeHash(img_hash::BlockMeanHash::create(1));
    computeHash(img_hash::ColorMomentHash::create());
}

You can measure the performance of the algorithms under different by this graph and pick the one suit by your needs.

image description

ps : At first I give BOVW a shot, the results are solid, but it take too many times to build the coed book and retrieve the features from image. Then I found image hash can help me boost up the speed(although it do not provide best accuracy).

2016-07-01 20:49:31 -0600 commented question I plan to recognize paper bills by denomination but i can't think of a way to do so ... it must be invariant of illumination, rotation and scale. can i use haar or LBP ? do you have any suggestions?

Since you need to deal with illumination, rotation and scale, I suggest you give bag of visual words(BOVW) or convolution neural network a try. opencv provide good tools to train your classifier base on BOVW, if you need a very easy to use cnn library, please google tiny-cnn.

2016-07-01 20:49:19 -0600 commented question I plan to recognize paper bills by denomination but i can't think of a way to do so ... it must be invariant of illumination, rotation and scale. can i use haar or LBP ? do you have any suggestions?

Since you need to deal with illumination, rotation and scale, I suggest you can give bag of visual words(BOVW) or convolution neural network a try. opencv provide good tools to train your classifier base on BOVW, if you need a very easy to use cnn library, please google tiny-cnn.

2016-06-19 00:57:18 -0600 marked best answer push back element to the column of cv::Mat

How could I push back the floating point value to the column of cv::Mat?

cv::Mat_<float> A;
A.push_back(0);
A.push_back(1);
A.push_back(2);
A.push_back(3);

Suppose I want to make the matrix become 2 rows 2 cols like this [0, 1; 2, 3].How could I push the value into the column of A with type "float"?

Edit : exception thrown

A = A.reshape(1,2); //this line would crash in openCV 2.4.5

cv::Mat_<float> B = A.reshape(1, 2); //ok, wouldn't crash, but the buffer are different
std::cout<<(B.data == A.data)<<std::endl; // answer is 0

Exception : "Assertion failed (!fixedType() || ((Mat)obj)->type() == mtype) in create, file /Users/yyyy/Downloads/opencv-2.4.5/modules/core/src/matrix.cpp, line 1345"*

Don't know where is the error occur, should I treat this as a bug and report it?

Edit 2 : unsafe codes?

I found something interesting, in the class Mat there are a flag

/*! includes several bit-fields:
     - the magic signature
     - continuity flag
     - depth
     - number of channels
 */
int flags;

The flags is int, that means the behavior of the sign bit may not work as the programmer expect. When we call reshape, the Mat will do some operation on the flag

hdr.flags = (hdr.flags & ~CV_MAT_CN_MASK) | ((new_cn-1) << CV_CN_SHIFT);

And the function fixedType() and type() use the flags to check the type of Mat

core/include/opencv2/core/mat.inl.hpp

inline
int Mat::type() const
{
  return CV_MAT_TYPE(flags);
}

modules/core/src/matrix.cpp

bool _OutputArray::fixedType() const
{
    return (flags & FIXED_TYPE) == FIXED_TYPE;
}
2016-06-19 00:50:32 -0600 commented answer Smoke detection

Sorry, theo2f, I cannot find a good enough solution to solve your problems, it is too hard to deal with jigger + moving camera for smoke detection. I will contact you after I found a good solution which could detect smoke on single frame.

2016-06-19 00:50:19 -0600 commented question Smoke detection

It works on the video sets quite well, but it do not guarantee on other environments. Besides, this algorithms only work if your camera is stable

2016-04-29 08:22:49 -0600 received badge  Popular Question (source)
2015-12-28 01:48:27 -0600 received badge  Notable Question (source)
2015-12-06 13:17:37 -0600 received badge  Notable Question (source)
2015-11-02 13:23:57 -0600 received badge  Nice Question (source)
2015-11-02 13:23:50 -0600 received badge  Notable Question (source)
2015-06-04 09:42:14 -0600 received badge  Popular Question (source)
2015-04-26 19:33:00 -0600 received badge  Popular Question (source)
2015-03-23 05:28:13 -0600 received badge  Popular Question (source)
2014-12-09 13:59:04 -0600 marked best answer Create a layer for artificial neural network of openCV2

According to this blog, it create the labels as this way

    cv::Mat layers = cv::Mat(4, 1, CV_32SC1); //create 4 layers

    layers.row(0) = cv::Scalar(2); //input layer accepts x and y
    layers.row(1) = cv::Scalar(10);//hidden layer
    layers.row(2) = cv::Scalar(15);//hidden layer
    layers.row(3) = cv::Scalar(1); //output layer returns 1 or -1

But in the book, it create the layers as following

Mat layers(1,3,CV_32SC1);
layers.at<int>(0)= TrainData.cols;
layers.at<int>(1)= nlayers;
layers.at<int>(2)= numCharacters;

1 : The blog use rows to save the parameters but the book use cols to save the parameters.Are they the same thing?Do I have to change the way of writing, reading the xml according to the way of saving the parameters(any issues I do not mention have to take care)?

2 : What is the order of the layers?As I guess(uncertain)

  1. The feature numbers of each sample
  2. number of layers
  3. ~ Last(assume 4 == last in this case) - 1
  4. Classes(The kinds of data want to classify. ex : '0', '1', ..., '9')
2014-12-09 13:57:13 -0600 marked best answer Where is the source codes of cv::getRectSubPix?

I would like to study the source codes of cv::getRectSubPix, but I can't find it in the module imgproc, do anyone know where could I find the source codes?Thanks

2014-12-09 13:57:04 -0600 marked best answer Draw the lines detected by cv::HoughLines

On this site(tutorial), it show us how to draw the lines detected by cv::HoughLines,but I can't understand how could it find out the Point between the lines.

    for( size_t i = 0; i < lines.size(); i++ )
  {
     float rho = lines[i][0], theta = lines[i][1];
     Point pt1, pt2;
     double a = cos(theta), b = sin(theta);
     double x0 = a*rho, y0 = b*rho;
     pt1.x = cvRound(x0 + 1000*(-b)); //??
     pt1.y = cvRound(y0 + 1000*(a)); //??
     pt2.x = cvRound(x0 - 1000*(-b)); //??
     pt2.y = cvRound(y0 - 1000*(a)); //??
     line( cdst, pt1, pt2, Scalar(0,0,255), 3, CV_AA);
  }

Another codes from the openCV2 cookbook.I could understand why the codes from the cookbook work but it is more verbose.

for(auto const &data : lines){
    float const rho = data[0];
    float const theta = data[1];

    if((theta < PI/4. || theta > 3. * PI/4.)){
        cv::Point pt1(rho / std::cos(theta), 0);
        cv::Point pt2( (rho - result.rows * std::sin(theta))/std::cos(theta), result.rows);
        cv::line(result, pt1, pt2, cv::Scalar(255), 1);
    }else if{
        cv::Point pt1(0, rho / std::sin(theta));
        cv::Point pt2(result.cols, (rho - result.cols * std::cos(theta))/std::sin(theta));
        cv::line(result, pt1, pt2, cv::Scalar(255), 1);
    }
}
2014-12-09 13:56:06 -0600 marked best answer Header files of sift in github

Studying the source codes of sift but can't find out where is the header files.Every folder from github are not included the header files(declaration) of the sift.

2014-12-09 13:53:10 -0600 marked best answer Do we need to optimize matrix operation of cv::Mat?

clean and easy to read, but this kind of operation may generate two temporary objects

foreground_current = (frame_current_ - (1 - Beta_) * background_current_) / Beta_; //#1

Hard to read and verbose

//can't alter the value of background_current
background_current_.copyTo(temp_);
temp_ *= 1 - Beta_; //can't use (Beta_ - 1) since it is negative
frame_current_.copyTo(foreground_current_);
foreground_current_ -= temp_;
foreground_mask_ /= Beta_;

or write a for loop for it?

//same as for loop
OCV::transform_channels<uchar>(frame_current_, background_current_, foreground_current_, [=](uchar fr, uchar bg)
    {
        return cv::saturate_cast<Type>((fr - (1 - Beta_) * bg) / Beta_);
    });

What I want to ask is, do openCV provide some optimization for operator overloading? With the help of expression template, it is possible to eliminate the temporary objects of #1. Do openCV2 support this kind of optimization?Thanks

2014-12-09 13:44:40 -0600 marked best answer Problem about the source codes of otsu-threshold

The codes from the files thresh.cpp, the function name is getThreshVal_Otsu_8u

if( std::min(q1,q2) < FLT_EPSILON || 
            std::max(q1,q2) > 1. - FLT_EPSILON )
            continue;

As far as I know,

q1 + q2 = 1--(1)
q1 = 1 - q2--(2)
q2 = 1 - q1--(3)

That means if

q1 < FLT_EPSILON

then 1 - q1 will satisfy

1 - q1 > 1 - FLT_EPSILON

In other words, if std::min(q1,q2) < FLT_EPSILON, then std::max(q1,q2) > 1. - FLT_EPSILON should satisfy too.So why do the codes need to do double check? Why don't just use

if( std::min(q1,q2) < FLT_EPSILON)
                continue;
2014-12-09 13:08:58 -0600 marked best answer c++ api of LogPolar transform of openCV

Do openCV2 provide a c++ api for LogPolar transform logpolar describe in this page?Can't find any api corresponding to this function.I search the api from the openCV doc and google but can't find anything related to c++ api.

2014-10-31 12:32:28 -0600 marked best answer openCV will drop C API support soon

From the pdf of ICVS2013(http://opencv.org/icvs2013.html), it say openCV will drop C API support soon.Do anyone know the details?Drop C API support means they will not develop any new api for C or they will discards all of the C API in the future?

I am a fans of openCV2 and do not like C API of openCV1, too verbose and no performance gain by using it, if openCV will discards all of the C API, I would have more reasons to push my colleagues move to c++ API and increase the chances to say goodbye to C API.

2014-06-28 06:52:40 -0600 received badge  Nice Question (source)
2014-06-20 01:46:23 -0600 marked best answer Create a memory continuous cv::Mat, any api could do that?
cv::Mat dst(src.size(), src.type());

I want to make sure the memory of the dst is continuous(without padding), how could I do that?

The most easiest answer is call the reshape after creation.

dst.reshape(0);

But how could I make sure it is continuous when construct?