Page 158 - python
P. 158

132



































                                 ภาพประกอบที่ 11.3 การแสดงตําแหนงพิกัดของโครงสรางภาพสองมิติ


                   ตัวอยางที่ 11.1 การเขียนโปรแกรมวาดรูปทรงสองพื้นฐานสองมิติ
                    %pylab inline

                    import numpy
                    import cv2
                    img = numpy.ones((400,600,3),numpy.uint8)*255
                    x = [10,20,40,130,143,150, 80,80,80,30,90,90,90,100]

                    y = [60,70,90,90,70,60,60,50,20,50, 60,50,30,50]
                    sx = 3.8 ; sy = 4
                    X = list(map(lambda a:a*sx, x))

                    Y = list(map(lambda a:a*xy, y))
                    def line(p1,p2):
                      cv2.line(img, (int(X[p1]),int(Y[p1])), (int(X[p2]),int(Y[p2])), (0,0,0), 2)


                    L = [[0,2],[2,3],[3,5],[0,5], [6,8], [8,9], [9,7], [10,12], [12,13], [13,11], [1,4]]
                    for i in L:
                      line(i[0],i[1])


                    r = 3  ;  thick = 5 ; c = (255,0,0)
                    for i in range(len(x)):
                      img = cv2.circle(img, (int(X[i]),int(Y[i])), r, c, thick)
                    plt.imshow(img);plt.show()
   153   154   155   156   157   158   159   160   161   162   163