Learn opencv--to draw comics with OpenCV

Source: Internet
Author: User

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?
  1. #include "Cv.h"
  2. #include "highgui.h"
  3. Using namespace CV;
  4. Using namespace std;
  5. int main ()
  6. {
  7. String name="D:/cartoon0.jpg";
  8. Mat Src1=imread (name,1);
  9. Mat img;
  10. //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,
  11. //<10 Basically no effect, >150 when the comic effect
  12. Bilateralfilter (src1,img,5,150,150);
  13. Bilateralfilter (img,src1,5,150,150);
  14. //img.copyto (SRC1);
  15. Imshow ("bilateral", SRC1);
  16. Waitkey (0);
  17. Mat src;
  18. Cvtcolor (Src1,src,cv_bgr2gray);
  19. //thick lines, larger and thicker, but with lots of noise.
  20. Mat IMGL;
  21. ///The third parameter ddepth represents the depth of the target image, and when ddepth=-1, it is consistent with the original image
  22. Laplacian (src,imgl,-1,3,1);
  23. Imshow ("Laplacian", IMGL);
  24. Waitkey (0);
  25. //Thin line
  26. Mat IMGC;
  27. Canny (src,imgc,30,90);
  28. Imshow ("Canny", IMGC);
  29. Waitkey (0);
  30. Mat Imgs,imgsx,imgsy,imgs0;
  31. Sobel (src,imgsx,-1,0,1);
  32. Sobel (src,imgsx,-1,1,0);
  33. Imgs=imgsx+imgsy;
  34. Sobel (src,imgs0,-1,1,1);
  35. Imshow ("Sobel0", imgS0);
  36. Imshow ("Sobel", IMGs);
  37. Waitkey (0);
  38. Mat Imgtotal;
  39. IMGTOTAL=IMGC+IMGS+IMGL;
  40. //imgtotal.convertto (IMGTOTAL,CV_32FC1);
  41. Normalize (Imgtotal,imgtotal,255,0,cv_minmax);
  42. Gaussianblur (Imgtotal,imgtotal,size (3,3), 3);
  43. Threshold (IMGTOTAL,IMGTOTAL,100,255,THRESH_BINARY_INV);
  44. Imshow ("Total", imgtotal);
  45. Waitkey (0);
  46. Mat imgTotalC3;
  47. Cvtcolor (IMGTOTAL,IMGTOTALC3,CV_GRAY2BGR);
  48. Bitwise_and (SRC1,IMGTOTALC3,SRC1);
  49. Imshow ("Result", SRC1);
  50. Waitkey (0);
  51. Name.insert (One,"_edge");
  52. Imwrite (NAME,SRC1);
  53. /* 
  54. Mat img (IMGTOTAL.ROWS,IMGTOTAL.COLS,CV_32FC1);
  55. for (int i=0;i
  56. {
  57. uchar* p= (uchar*) (Imgtotal.ptr () +i*imgtotal.step);
  58. for (int j=0;j
  59. {
  60. if (imgtotal.at<float> (i,j) ==0)
  61. Img.at<float> (I,J) = 1;
  62. }
  63. }
  64. Imshow ("Reverse", IMG);
  65. Waitkey (0);
  66. */
  67. /* 
  68. Mat IMGSC;
  69. ScHARR (src,imgsc,-1,1,0);
  70. Imshow ("ScHARR", IMGSC);
  71. Waitkey (0);
  72. */
  73. }

from:http://blog.csdn.net/yangtrees/article/details/7544481

Learn opencv--to draw comics with OpenCV

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.