Qt 5.3 under OpenCV 2.4.11 Development (13) Corrosion and expansion

Source: Internet
Author: User

Default corrosion and expansion operation:

#include <QCoreApplication> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp > #include <opencv2/imgproc/imgproc.hpp>using namespace cv;int main () {       Mat src = imread ("Lena.jpg", 0);    Mat DST, eroded, dilated;    Mat Element (7, 7, cv_8u, Scalar (1));    Threshold (SRC, DST, 255, THRESH_BINARY_INV);//binary image value    Namedwindow ("DST", 0);    Imshow ("DST", DST);    Erode (DST, eroded, Mat ());//Corrosion    Namedwindow ("eroded", 0);    Imshow ("eroded", eroded);    Dilate (DST, dilated, Mat ());//Swell    Namedwindow ("dilated", 0);    Imshow ("dilated", dilated);    Waitkey (0);}

Function Description:

1. The threshold function is used to process the grayscale image into two-valued image, the first parameter is the input grayscale image, the second parameter is the output two value image, the third parameter is the threshold value, the fourth parameter is the data that satisfies the threshold condition of the pixel, and the fifth parameter is the positive and negative switch. There is also a thresh_binary, the opposite effect.



After the strength factor has been added:

#include <QCoreApplication> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp > #include <opencv2/imgproc/imgproc.hpp>using namespace cv;int main () {       Mat src = imread ("Lena.jpg", 0);    Mat DST, eroded, dilated;    Mat Element (7, 7, cv_8u, Scalar (1));    Threshold (SRC, DST, 255, THRESH_BINARY_INV);    Namedwindow ("DST", 0);    Imshow ("DST", DST);    Erode (DST, eroded, element);    Namedwindow ("eroded", 0);    Imshow ("eroded", eroded);    Dilate (DST, dilated, Element);    Namedwindow ("dilated", 0);    Imshow ("dilated", dilated);    Waitkey (0);}

Function Description:

1, Element matrix is the strength of corrosion and expansion, here is the structure of 7*7 elements.



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Qt 5.3 under OpenCV 2.4.11 Development (13) Corrosion and expansion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.