Opencv3.3.1+vs2015+c++ implementation directly on the image to draw the mask, save the mask picture

Source: Internet
Author: User

Zoo Right-click Blue, save as K

#include "opencv2\imgproc\imgproc.hpp"//Gaussian Blur#include "OPENCV2\CORE\CORE.HPP"//BASIC OpenCV Structures (Cv::mat, Scalar) #include <opencv2\highgui\highgui.hpp>//OpenCV window I/o#include <iostream>//For Stand ARD I/o#include <string>//For Strings#include <iomanip>//for controlling float print precision#include <sstream>//String to number Conversionusing namespace cv;using namespace std;
BOOL Rbuttondown = False;bool Lbuttondown = false;int Numusedbins = 0;float variancesquared = 0;int ScribbleRadius = 10; Mat inputimg = Imread ("0.jpg", 3), showimg = Imread ("0.jpg", 3); Mat Fgscribblemask; Mat bgscribblemask;static void Onmouse (int event, int x, int y, int, void*) {cout << "on Mouse: (" << x <&lt ; "," << y << ")" <<endl;if (event = = Cv_event_lbuttondown) {Lbuttondown = true;} else if (event = = Cv_event_rbuttondown) {Rbuttondown = true;} else if (event = = Cv_event_lbuttonup) {Lbuttondown = false;} else if (event = = Cv_event_rbuttonup) {Rbuttondown = false;} else if (event = = Cv_event_mousemove) {if (Rbuttondown) {//Scribble the Backgroundcircle (Bgscribblemask, point (x, y), Scri Bbleradius, 255,-1); Circle (showimg, point (x, y), Scribbleradius, Cv_rgb (0, 0, 255), 1);} else if (Lbuttondown) {//Scribble the Foregroundcircle (showimg, point (x, y), Scribbleradius, Cv_rgb (255, 0, 0), 1); circle (Fgscribblemask, point (x, y), Scribbleradius, 255,-1);}} Imshow ("DRaw ", showimg); Imshow (" FG Mask ", Fgscribblemask); Imshow (" BG Mask ", Bgscribblemask);} int main () {bgscribblemask.create (2, Inputimg.size, cv_8uc1); bgscribblemask = 0; Fgscribblemask.create (2, Inputimg.size, cv_8uc1), Fgscribblemask = 0;namedwindow ("Draw"), Imshow ("Draw", showimg); Namedwindow ("input"); imshow ("Input", inputimg); Setmousecallback ("Draw", Onmouse, 0);  while (1) {char key = Waitkey (0); if (key = = ' K ') {imwrite ("1123.jpg", fgscribblemask); cout << "successed";}}

  

Opencv3.3.1+vs2015+c++ implementation directly on the image to draw the mask, save the mask picture

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.