Busy time with OpenCV painting comics is also very interesting, although the effect is not good (up to the effect achieved above),
Parameters need to be adjusted, or large-sized and small noise image is more appropriate
And can be familiar with a variety of filtering operations such as: bilateral filtering;
[CPP]View PlainCopyprint?
- #include "Cv.h"
- #include "highgui.h"
- Using namespace CV;
- Using namespace std;
- int main ()
- {
- String name="D:/cartoon0.jpg";
- Mat Src1=imread (name,1);
- Mat img;
- //Bilateral filtering, the 3rd parameter D can be said d>5 when not real-time processing, the last two parameters are the Sigma parameter, generally the same,
- //<10 Basically no effect, >150 when the comic effect
- Bilateralfilter (src1,img,5,150,150);
- Bilateralfilter (img,src1,5,150,150);
- //img.copyto (SRC1);
- Imshow ("bilateral", SRC1);
- Waitkey (0);
- Mat src;
- Cvtcolor (Src1,src,cv_bgr2gray);
- //thick lines, larger and thicker, but with lots of noise.
- Mat IMGL;
- ///The third parameter ddepth represents the depth of the target image, and when ddepth=-1, it is consistent with the original image
- Laplacian (src,imgl,-1,3,1);
- Imshow ("Laplacian", IMGL);
- Waitkey (0);
- //Thin line
- Mat IMGC;
- Canny (src,imgc,30,90);
- Imshow ("Canny", IMGC);
- Waitkey (0);
- Mat Imgs,imgsx,imgsy,imgs0;
- Sobel (src,imgsx,-1,0,1);
- Sobel (src,imgsx,-1,1,0);
- Imgs=imgsx+imgsy;
- Sobel (src,imgs0,-1,1,1);
- Imshow ("Sobel0", imgS0);
- Imshow ("Sobel", IMGs);
- Waitkey (0);
- Mat Imgtotal;
- IMGTOTAL=IMGC+IMGS+IMGL;
- //imgtotal.convertto (IMGTOTAL,CV_32FC1);
- Normalize (Imgtotal,imgtotal,255,0,cv_minmax);
- Gaussianblur (Imgtotal,imgtotal,size (3,3), 3);
- Threshold (IMGTOTAL,IMGTOTAL,100,255,THRESH_BINARY_INV);
- Imshow ("Total", imgtotal);
- Waitkey (0);
- Mat imgTotalC3;
- Cvtcolor (IMGTOTAL,IMGTOTALC3,CV_GRAY2BGR);
- Bitwise_and (SRC1,IMGTOTALC3,SRC1);
- Imshow ("Result", SRC1);
- Waitkey (0);
- Name.insert (One,"_edge");
- Imwrite (NAME,SRC1);
- /*
- Mat img (IMGTOTAL.ROWS,IMGTOTAL.COLS,CV_32FC1);
- for (int i=0;i
- {
- uchar* p= (uchar*) (Imgtotal.ptr () +i*imgtotal.step);
- for (int j=0;j
- {
- if (imgtotal.at<float> (i,j) ==0)
- Img.at<float> (I,J) = 1;
- }
- }
- Imshow ("Reverse", IMG);
- Waitkey (0);
- */
- /*
- Mat IMGSC;
- ScHARR (src,imgsc,-1,1,0);
- Imshow ("ScHARR", IMGSC);
- Waitkey (0);
- */
- }
from:http://blog.csdn.net/yangtrees/article/details/7544481
Learn opencv--to draw comics with OpenCV