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 << ; "," << 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