Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy segment from the image?

I have Emgu image :

Image<Bgr,byte> image = new Image<Bgr,byte>("image.jpg"); 

Here is how the file(image.jpg) looks like:

enter image description here

All pixels that inside red-yellow triangle I want to copy to the new image called:

Image<Bgr,byte> copiedSegment;

Any idea how to implement it if I have coordinates all coordinates of the triangle contour.

Thank you in advance.

like image 272
Michael Avatar asked Oct 19 '25 04:10

Michael


1 Answers

In the opencv c++ api you can just use the matrix copy function with a mask composed of your triangular components.

Mat image = imread("image.jpg",CV_LOAD_IMAGE_COLOR);
vector<Point> triangleRoi;
Mat mask;

//draw your trianlge on the mask
cv::fillConvexPoly(mask, triangleRoi, 255);

Mat copiedSegment;
image.copyTo(copiedSegment,mask);

You should beable to write some similar code in emgu based on this.

like image 159
Element Avatar answered Oct 21 '25 16:10

Element