Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The problem about iteration of gpumat

I want to plant a section of class Blender to support gpumat . `class CV_EXPORTS Blender { public: virtual ~Blender() {}

enum { NO, FEATHER, MULTI_BAND };
static Ptr<Blender> createDefault(int type, bool try_gpu = false);

void prepare(const std::vector<Point> &corners, const std::vector<Size> &sizes);
virtual void prepare(Rect dst_roi);
virtual void feed(const Mat &img, const Mat &mask, Point tl);
virtual void blend(Mat &dst, Mat &dst_mask);

protected: Mat dst_, dst_mask_; ` And when iterating a GpuMat matrix ,My project always crash and stop at a unfix row.But I have use the function "createContinuous"to create a continous matrix.

enter code here#include "blend_n.h"

include "ImageJoint.h"

using namespace gpu; Ptr<blender_n> Blender_n::createDefault() { return new Blender_n();

CV_Error(CV_StsBadArg, "unsupported blending method");
return NULL;

}

void Blender_n::prepare(const vector<point> &corners, const vector<size> &sizes) { prepare(resultRoi(corners, sizes)); }

void Blender_n::prepare(Rect dst_roi) {

dst_= cv::gpu::createContinuous(dst_roi.size(),CV_16UC3);// CV_16SC3);
dst_.setTo(Scalar::all(0));
dst_mask_.create(dst_roi.size(), CV_8U);
dst_mask_.setTo(Scalar::all(0));
dst_roi_ = dst_roi;

}

void Blender_n::feed(const GpuMat &img, const Mat &mask, Point tl) {

CV_Assert(img.type() == CV_16UC3);//CV_16SC3);
CV_Assert(mask.type() == CV_8U);
int dx = tl.x - dst_roi_.x;
int dy = tl.y - dst_roi_.y;

int rows = img.rows;
int cols = img.cols;


for (int y = 0; y < rows; ++y)
{
    const Point3_<short> *src_row = img.ptr<Point3_<short> >(y);
    Point3_<short> *dst_row = dst_.ptr<Point3_<short> >(dy + y);
    const uchar *mask_row = mask.ptr<uchar>(y);
    uchar *dst_mask_row = dst_mask_.ptr<uchar>(dy + y);
    cout<<y<<endl;
    for (int x = 0; x < img.cols; ++x)
    {
        if (mask_row[x])
            dst_row[dx + x] = src_row[x];
        dst_mask_row[dx + x] |= mask_row[x];
    }
}

}

void Blender_n::blend(GpuMat &dst, Mat &dst_mask) { GpuMat k1; k1.upload(dst_mask_); dst_.setTo(Scalar::all(0), k1(0) ); dst = dst_; dst_mask = dst_mask_; dst_.release(); dst_mask_.release(); }` when I use the function feed ,the project always stop at dst_row[dx + x] = src_row[x];

click to hide/show revision 2
gpumat blend iterate

The problem about iteration of gpumat

I want to plant a section of class Blender to support gpumat . `class .just like above

 class CV_EXPORTS Blender
{
    {

public:
    virtual ~Blender() {}

{}
    enum { NO, FEATHER, MULTI_BAND };
 static Ptr<Blender> createDefault(int type, bool try_gpu = false);

 void prepare(const std::vector<Point> &corners, const std::vector<Size> &sizes);
 virtual void prepare(Rect dst_roi);
 virtual void feed(const Mat &img, const Mat &mask, Point tl);
 virtual void blend(Mat &dst, Mat &dst_mask);
    protected:
        Mat dst_, dst_mask_;
      }

protected: Mat dst_, dst_mask_; ` And when iterating a GpuMat matrix ,My project always crash and stop at a unfix row.But I have use the function "createContinuous"to create a continous matrix.

enter code here#include "blend_n.h"
class Blender_n
{
public:
    virtual ~Blender_n() {}

    //enum { NO, FEATHER, MULTI_BAND };
    static Ptr<Blender_n> createDefault();

    void prepare(const std::vector<Point> &corners, const std::vector<Size> &sizes);
    virtual void prepare(Rect dst_roi);
    virtual void feed(const gpu::GpuMat &img, const Mat &mask, Point tl);
    virtual void blend(gpu::GpuMat &dst, Mat &dst_mask);

protected:
    gpu::GpuMat dst_;Mat dst_mask_;
    Rect dst_roi_;
};

include "ImageJoint.h"

the functions like above

#include "blend_n.h"
using namespace gpu;
Ptr<blender_n> Ptr<Blender_n> Blender_n::createDefault()
{
    return new Blender_n();

Blender_n();

    CV_Error(CV_StsBadArg, "unsupported blending method");
 return NULL;

}

} void Blender_n::prepare(const vector<point> vector<Point> &corners, const vector<size> vector<Size> &sizes) { prepare(resultRoi(corners, sizes)); }

} void Blender_n::prepare(Rect dst_roi) {

 dst_= cv::gpu::createContinuous(dst_roi.size(),CV_16UC3);// CV_16SC3);
 dst_.setTo(Scalar::all(0));
 dst_mask_.create(dst_roi.size(), CV_8U);
 dst_mask_.setTo(Scalar::all(0));
 dst_roi_ = dst_roi;

}

} void Blender_n::feed(const GpuMat &img, const Mat &mask, Point tl) {

{

    CV_Assert(img.type() == CV_16UC3);//CV_16SC3);
 CV_Assert(mask.type() == CV_8U);
 int dx = tl.x - dst_roi_.x;
 int dy = tl.y - dst_roi_.y;

 int rows = img.rows;
 int cols = img.cols;


 for (int y = 0; y < rows; ++y)
{
    {
        const Point3_<short> *src_row = img.ptr<Point3_<short> >(y);
     Point3_<short> *dst_row = dst_.ptr<Point3_<short> >(dy + y);
     const uchar *mask_row = mask.ptr<uchar>(y);
     uchar *dst_mask_row = dst_mask_.ptr<uchar>(dy + y);
     cout<<y<<endl;
     for (int x = 0; x < img.cols; ++x)
    {
    {
            if (mask_row[x])
             dst_row[dx + x] = src_row[x];
         dst_mask_row[dx + x] |= mask_row[x];
    }
    }
    }
}

void Blender_n::blend(GpuMat &dst, Mat &dst_mask)
{
    GpuMat k1;
    k1.upload(dst_mask_);
    dst_.setTo(Scalar::all(0), k1 );
    dst = dst_;
    dst_mask = dst_mask_;
    dst_.release();
    dst_mask_.release();
}

}

void Blender_n::blend(GpuMat &dst, Mat &dst_mask) { GpuMat k1; k1.upload(dst_mask_); dst_.setTo(Scalar::all(0), k1(0) ); dst = dst_; dst_mask = dst_mask_; dst_.release(); dst_mask_.release(); }` when I use the function feed ,the project always funtion feed,it alway stop at " dst_row[dx + x] = src_row[x];src_row[x];".And the number of rows is random.Did someone try to iterate gpumat and meet the same problem?thank for your reply!