18, OpenCV Python Simple implementation of a picture generation (similar to the vibrato generated letter portrait)

Source: Internet
Author: User

1 __author__="WSX"2 ImportCv2 as CV3 ImportNumPy as NP4 5 defLocal_threshold (IMG):#Local threshold value6Gray = Cv.cvtcolor (IMG, CV. Color_bgr2gray)#change to Grayscale first7binary = Cv.adaptivethreshold (gray, 255, CV. Adaptive_thresh_gaussian_c, CV. Thresh_binary, 25, 10,)#255 Maximum Value8     #There are two ways to adaptive_thresh_gaussian_c (mean with weights) and adaptive_thresh_mean_c (and mean comparison)9     #blockSize must be an odd number, C is a constant (the average of each pixel block and the larger the mean than the extra C ... Less than C)Ten     #ret threshold, binary two value image OneCv.imshow ("binary", binary) A     returnbinary -  - defJinzita (Level, IMG): thetemp =img.copy () -Level = Level -Pyr_img = [] -      forIinchRange (level): +DST = Cv.pyrdown (temp)#Pyrup and Pyrdown opposite -temp =dst.copy () +     returnTemp A  at defresult (binary): -W, h = binary.shape[:2] -     Print(binary) -     Print(w,h) -     #temp = Np.zeros ((w, h)) -     #temp = List (temp) in     #temp = []; tt = [] -With open ("Result.txt","r+") as F: to          forIinchRange (W): +              forJinchRange (h): -                 ifBINARY[I,J] = =0: thetemp ="0" *                 elifBINARY[I,J] = = 255: $temp ="1"Panax Notoginseng f.write (temp) -F.write ("\ r \ n") the f.close () +     #print (Temp.shape) A defMain (): theimg = Cv.imread ("1.JPG") +     #Cv.namedwindow ("Show", CV. Window_autosize) -Cv.imshow ("Show", IMG) $t = Jinzita (3, IMG) $binary=local_threshold (t) - result (binary) - cv.waitkey (0) the cv.destroyallwindows () - WuyiMain ()

18, OpenCV Python Simple implementation of a picture generation (similar to the vibrato generated letter portrait)

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.