Ask Your Question

yode's profile - activity

2020-10-28 08:14:49 -0600 received badge  Popular Question (source)
2020-08-20 07:51:29 -0600 received badge  Popular Question (source)
2020-04-28 02:28:30 -0600 received badge  Popular Question (source)
2019-05-27 06:38:03 -0600 marked best answer inconsistent behavior about ROI calculation

As we know:

Mat img(7, 8, CV_8UC1, Scalar(0));
Mat com = (Mat_<uchar>(4, 3) << 255, 0, 0, 255, 255, 0, 255, 255, 0, 255, 255, 255);
img(Rect(1, 2, 3, 4)) += com;

We will get a img like this:

This is out understandable behavior because we do a calculation in the same ROI. But why this code:

Mat img(7, 8, CV_8UC1, Scalar(0));
Mat com = (Mat_<uchar>(4, 3) << 255, 0, 0, 255, 255, 0, 255, 255, 0, 255, 255, 255);
img(Rect(1, 2, 3, 4)) = com;

cannot get a same result? The img is empty image still:

I'm confusion about it. Or do I have missed something?

2019-05-27 04:46:11 -0600 commented question inconsistent behavior about ROI calculation

@HYPEREGO I have edited the question.

2019-05-27 04:45:31 -0600 edited question inconsistent behavior about ROI calculation

inconsistent behavior about ROI calculation As we know: Mat img(7, 8, CV_8UC1, Scalar(0)); Mat com = (Mat_<uchar>

2019-05-27 04:45:11 -0600 edited question inconsistent behavior about ROI calculation

inconsistent behavior about ROI calculation As we know: Mat img(7, 8, CV_8UC1, Scalar(0)); Mat com = (Mat_<uchar>

2019-05-27 01:31:45 -0600 asked a question inconsistent behavior about ROI calculation

inconsistent behavior about ROI calculation As we know: Mat img(7, 8, CV_8UC1, Scalar(0)); Mat com = (Mat_<uchar>

2019-04-11 08:57:03 -0600 edited question A bug of opencv4.1.0?

A bug of opencv4.1.0? I see the ChangeLog about opencv4.1 about new function calcOpticalFlowSparseRLOF. So I give a try:

2019-04-11 08:55:29 -0600 edited question A bug of opencv4.1.0?

A bug of opencv4.1.0? I see the ChangeLog about opencv4.1 about new function calcOpticalFlowSparseRLOF. So I give a try:

2019-04-11 08:54:59 -0600 asked a question A bug of opencv4.1.0?

A bug of opencv4.1.0? I see the ChangeLog about opencv4.1 about new function calcOpticalFlowSparseRLOF. So I give a try:

2018-11-23 03:13:21 -0600 commented answer Same function but different result

Could you tell me why the img is 8u still here?

2018-08-16 08:20:57 -0600 asked a question cv::reg::MapperGradShift produce worse result in the given test code

cv::reg::MapperGradShift produce worse result in the given test code Actually, I have read the official documentation he

2018-08-14 00:35:20 -0600 edited question Is possible convert the Mat with two channels into a vector<vector<int>>

Is possible convert the Mat with two channels into a vector<vector<int>> If I have a mat like Mat mat = (Ma

2018-08-13 13:48:48 -0600 asked a question Is possible convert the Mat with two channels into a vector<vector<int>>

Is possible convert the Mat with two channels into a vector<vector<int>> If I have a mat like Mat mat = (Ma

2018-05-22 05:15:43 -0600 edited question How to use Map class to implement image registration?

How to use Map class to implement image registration? Actually, I have read the official documentation here about class

2018-05-17 22:20:17 -0600 asked a question How to use Map class to implement image registration?

How to use Map class to implement image registration? Actually, I have read the official documentation here. And This is

2018-04-05 04:27:20 -0600 marked best answer How to use push_back

The forum have some related post for how to use push_back. I can use it like

Mat mat = (Mat_<uchar>(2, 4) << 5, 6, 0, 4, 0, 1, 9, 9);
Mat mat2 = (Mat_<uchar>(2, 4) << 5, 77, 0, 4, 2, 3, 9, 6);
//success
mat.push_back(mat2);

But I note there are other two usage when I use F12 to see the definition. Such as

/** @brief Adds elements to the bottom of the matrix.
The methods add one or more elements to the bottom of the matrix. They emulate the corresponding
method of the STL vector class. When elem is Mat , its type and the number of columns must be the
same as in the container matrix.
@Param elem Added element(s).
 */
template<typename _Tp> void push_back(const _Tp& elem);

/** @overload
@Param elem Added element(s).
*/
template<typename _Tp> void push_back(const Mat_<_Tp>& elem);

/** @overload
@Param elem Added element(s).
*/
template<typename _Tp> void push_back(const std::vector<_Tp>& elem);

/** @overload
@Param m Added line(s).
*/
void push_back(const Mat& m);

I think it supports push_back a vector into Mat, but I can not run it normally

//fail
vector<vector<uchar>> v1 = { { 5, 77, 0, 4 },{ 2, 3, 9, 6 } };
mat.push_back(v1);
//fail
vector<uchar> v2 = { 2, 3, 9, 6 };
mat.push_back(v2);

Can anybody tell me something? What have I missed something?

2018-04-05 03:57:48 -0600 commented answer How to use push_back

And it's seem 2d-vector cannot be convert into Mat? such as the code will fail vector<vector<uchar>> v = {

2018-04-05 03:51:18 -0600 commented answer How to use push_back

Hi, thanks for answer. But your Mat(v2).t() is a Mat but not a vector? It is same with my first success example

2018-04-05 03:49:30 -0600 commented question How to use push_back

@berak I will keep that in mind.

2018-04-04 14:24:03 -0600 edited question How to use push_back

How to use push_back Corss post here The forum have some related post for how to use push_back. I can use it like M

2018-04-04 14:23:21 -0600 edited question How to use push_back

How to use push_back Corss post here The forum have some related post for how to use push_back. I can use it like M

2018-04-04 12:27:41 -0600 edited question How to use push_back

How to use push_back Corss post here The forum have some related post for how to use push_back. I can use it like M

2018-04-04 12:26:48 -0600 edited question How to use push_back

How to use push_back Corss post here The forum have some related post for how to use push_back. I can use it like M

2018-04-04 12:22:52 -0600 edited question How to use push_back

How to use push_back The forum have some related post for how to use push_back. I can use it like Mat mat = (Mat_<u

2018-04-04 12:20:51 -0600 asked a question How to use push_back

How to use push_back The forum have some related post for how to use push_back. I can use it like Mat mat = (Mat_<u

2018-04-02 21:48:08 -0600 marked best answer How to make the function can process different type image

Cross post here


I have build two functions with different name to drop the specfiy lines from difference Mat object, this is the code:

Mat drop_rows_int(Mat mat, vector<int> v) {
    Mat mat_new = Mat::zeros(mat.rows - v.size(), mat.cols, CV_32SC1);
    for (int i = 0, j = 0; i < mat.rows; i++) {
        if (find(v.begin(), v.end(), i) != v.end())
        {
            continue;
        }
        else
        {
            int*pmat = mat.ptr<int>(i);
            int*pmat_new = mat_new.ptr<int>(j);
            for (int w = 0; w < mat.cols; w++) {
                pmat_new[w] = pmat[w];
            }
            j++;
        }
    }
    return mat_new;
}

Mat drop_rows_uchar(Mat mat, vector<int> v) {
    Mat mat_new = Mat::zeros(mat.rows - v.size(), mat.cols, CV_8UC1);
    for (int i = 0, j = 0; i < mat.rows; i++) {
        if (find(v.begin(), v.end(), i) != v.end())
        {
            continue;
        }
        else
        {
            uchar*pmat = mat.ptr<uchar>(i);
            uchar*pmat_new = mat_new.ptr<uchar>(j);
            for (int w = 0; w < mat.cols; w++) {
                pmat_new[w] = pmat[w];
            }
            j++;
        }
    }
    return mat_new;
}

Then I can use it in my main() function like

int main()
{
    Mat mat_uchar = (Mat_<uchar>(5, 4) << 5, 6, 0, 4, 0, 1, 9, 9, 100, 3, 5, 8, 200, 33, 1, 4, 8, 88, 23, 6);
    Mat new_mat_uchar = drop_rows_uchar(mat_uchar, {2,4});

    Mat mat_int = (Mat_<int>(5, 4) << 5, 6, 0, 4, 0, 1, 9, 9, 100, 3, 5, 8, 200, 33, 1, 4, 8, 88, 23, 6);
    Mat new_mat_int = drop_rows_int(mat_int, { 2,4 });

        return 0;
}

Yes, I made it. but as I know, the Mat can have 7 kinds of depth, such as CV_8U, CV_8S, CV_16U, CV_16S, CV_32S, CV_32F and CV_64F, So I have to build 7 functions with different name to do such thing?? Can anyone tell me how to use one function to implement it??

2018-04-02 06:29:54 -0600 commented answer How to make the function can process different type image

Funny. It works..

2018-04-02 05:24:57 -0600 commented answer How to make the function can process different type image

Sorry, my last comment misses some information. I don't know why some comment always will fail sometimes. I mean I want

2018-04-02 05:24:14 -0600 commented answer How to make the function can process different type image

Sorry, my last comment misses some information. I don't know why some comment always will fail sometimes. I mean I want

2018-04-02 05:02:53 -0600 commented answer How to make the function can process different type image

Could you tell me how to set a default value for my this template function?

2018-04-02 05:02:17 -0600 commented answer How to make the function can process different type image

Could you tell me how to set a default value for my this template function?

2018-04-02 03:16:18 -0600 commented answer How to make the function can process different type image

Glad to see your help again. Thanks very much.

2018-04-02 01:43:55 -0600 edited question How to make the function can process different type image

How to make the function can process different type image Cross post here I have build two functions with different n

2018-04-02 01:42:35 -0600 edited question How to make the function can process different type image

How to make the function can process different type image Cross post here I have build two functions with different n

2018-04-02 01:38:41 -0600 asked a question How to make the function can process different type image

How to make the function can process different type image I have build two function to drop the specfiy lines from diffe

2018-02-08 13:18:18 -0600 received badge  Self-Learner (source)
2018-02-08 02:01:14 -0600 answered a question How to remove those specified label component by fastest method

This is my current answer, I have increased the 99s to 0.004s now Mat img(1000, 2000, CV_8UC1); randu(img, Scalar(0), S

2018-02-07 21:03:10 -0600 commented question How to remove those specified label component by fastest method

@LBerger Hi guru, drop_label include some discontinuous labels maybe, I just make a example for specify my case...

2018-02-07 21:01:56 -0600 commented question How to remove those specified label component by fastest method

@LBerger Hi guru, drop_label include some discontinuous labels, I just make a example for specify my case...

2018-02-07 07:11:49 -0600 edited question How to remove those specified label component by fastest method

How to remove those specified label component by fastest method Cross post here Suppose I have an such binary image

2018-02-07 07:11:12 -0600 edited question How to remove those specified label component by fastest method

How to remove those specified label component by fastest method Cross post here Suppose I have an such binary image

2018-02-07 07:05:09 -0600 asked a question How to remove those specified label component by fastest method

How to remove those specified label component by fastest method Suppose I have an such binary image Mat img(1000, 2000,

2018-01-24 10:00:09 -0600 marked best answer How to get a connected component in one Mat

I have such image

I hope to get one connected component in one Mat with an efficient method. So I have write such code to implement it.

 #include<opencv.hpp>
using namespace std;
using namespace cv;

int main() {

    Mat bin_img = Mat::zeros(10, 10, CV_8UC1);
    rectangle(bin_img, Point(1, 2), Point(3, 4), Scalar(255), -1);
    circle(bin_img, Point(5, 7), 2, Scalar(255), -1);

    int img_height = bin_img.rows, img_width = bin_img.cols;
    Mat labels;
    int n = connectedComponents(bin_img, labels);
    vector<Mat> masks(n - 1, Mat::zeros(bin_img.size(), CV_8UC1));

    Mat mask1 = masks[0];
    Mat mask2 = masks[1];
    for (int i = 0; i < img_height; i++)
    {
        int*plabels = labels.ptr<int>(i);
        for (int j = 0; j < img_width; j++)
        {
            if (plabels[j] != 0)
            {
                uchar* pmask = masks[plabels[j] - 1].ptr<uchar>(i);
                pmask[j] = 255;
            }
        }
        cout << endl;

    }
    for (int i = 0; i < n - 1; i++)
        imshow(to_string(i), masks[i]);

    waitKey(0);
    return 0;
}

But I don't know why all my element in vector masks is same totally.


update

Of course, I know there are some method can do this, such as compare in fllowing anser or inRange or operator ==. But I hope to use .ptr method here. Could anybody can give me a hand?