Ask Your Question
0

Adding an user defined object to Mat Object

asked 2016-02-18 05:35:44 -0600

santhoshkelathodi gravatar image

Anyone knows or have some sample code where a user defined object ( for example of a class myClassX) can be added to a mat Object.

Example

Something like this -> But definitely the below program is not compiling. is there any way to store user defined objects in Mat Object?

MyClass m[2][2];
Mat M(2, 2, MyClass, m);
MyClass Obj;
MyClassObj.at<MyClass>(0, 1) = Obj;
edit retag flag offensive close merge delete

Comments

2

Opencv is used for image processing and only type described here are authorized

LBerger gravatar imageLBerger ( 2016-02-18 06:30:44 -0600 )edit

Have you tried to add the element directly in the Mat? Why do you need a custom object? What does it represent? Does it contains numbers? "The class Mat represents an n-dimensional dense numericalsingle-channel or multi-channel array"

Maybe you can use the template class (or OpenCV3 docs)

thdrksdfthmn gravatar imagethdrksdfthmn ( 2016-02-18 06:36:12 -0600 )edit

1)As I understand Mat object is multidimensional array mainly used for image manipulation. I wanted to represent more information about the image for each of the pixel for one of my research purpose.For me it made more sense to include the information in the pixel position if I want to mark the pixel or to store some additional information. 2)Mat is only for image manipulation? 3) Have you tried to add the element directly in the Mat? Santhosh>Yes Why do you need a custom object? What does it represent? Does it contains numbers? Santhosh>For example to flag a pixel.Or for example in case of some feature extraction of pixel.I want to store feature information at the pixel.contains no or text "The class Mat represents an n-dimensional dense numericalsingle-channel or multi-channel array

santhoshkelathodi gravatar imagesanthoshkelathodi ( 2016-02-22 03:54:26 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-02-22 06:53:51 -0600

thdrksdfthmn gravatar image

What I would do in your place is to create some additional classes that may help. For example:

  • an image that has some pixels marked can be represented by a mask that has non-zero values in the positions of marked pixels:

    class ImageWithMask { private: cv::Mat image // initial image; cv::Mat mask; // mask that marks just the wanted pixels public: // constructor + methods };

You can also use the existent functions for manipulating the image just in the wanted pixels or not (as you can see, there are a lot of functions that have the mask parameter for applying the transformation just in special places)

  • You can also create another class that have information about some pixels you can create some other class that contains information about one pixel:

    class PixelInfo { private: cv::Point position; std::vector< float > featureDescriptors; // ... };

But this is already implemented with keypoints and descriptors. You can extract the descriptors once for each pixel and store it in some variable.

IMHO it is not a good practice to store exhaustive information about the image in each pixel position, You'll end up with "not enough memory" problems.

What you can do about the "no or text" pixels is to use the mask; maybe you can create 2 masks if needed...

edit flag offensive delete link more

Comments

What you said must be correct. I need to understand some more concepts about OpenCV. Ill understand them and get back. I am just a beginner. I hope you will bear with me if you think my question was trivial. :(. I ll get back on this. Thank you for the explanation

santhoshkelathodi gravatar imagesanthoshkelathodi ( 2016-02-22 11:21:52 -0600 )edit

Sorry, I did not want to upset you, but I was trying to tell how I would think. If you have a "descriptor extraction" in each pixel, then this will become interesting for your approach, even if it gets a little redundant, because a descriptor is computed over a region, not only in one pixel... :)

thdrksdfthmn gravatar imagethdrksdfthmn ( 2016-02-23 07:54:55 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-02-18 05:35:44 -0600

Seen: 192 times

Last updated: Feb 22 '16