Exemple #1
0
def main(dir_path, save_name):
    """TODO: Docstring for main.

    :arg1: TODO
    :returns: TODO

    """
    patten = os.path.join(dir_path, "*.png")
    images = glob.glob(patten)
    images.sort()
    fourcc = cv2.VideoWriter_fourcc(*'XVID')
    out = cv2.VideoWriter(save_name, fourcc, 10, (1280, 720))
    # out = cv2.VideoWriter(save_name, fourcc, 10, (640, 480))

    for img_name in images:
        print(img_name)
        img = cv2.imread(img_name)
        out.write(img)

        cv2.imshow('frame', img)
        if (cv2.waitKey(1) & 0xFF == ord('q')):
            break

    out.release()
    cv2.destoryAllWindow()
Exemple #2
0
def showImage3():
    img = cv2.imread(imgfile, cv2.IMREAD_COLOR)
    cv2.imshow('model', img)

    # key board data enter
    k = cv2.waitKey(0) & 0xFF

    if k == 27:
        cv2.destoryAllWindow()
    elif k == ord('c'):  # if c == copy
        cv2.imwrite('image/model_copy.jpg', img)
        cv2.destroyAllWindows()
Exemple #3
0
file_dst = 'picture/g_correction.png'

img_src = cv2.imread(file_src, -1)

cv2.namedWindow('src')
cv2.namedWindow('g_correction')

#ルックアップテーブル作成
Y = np.ones((256, 1), dtype = 'uint8') * 0              #配列[256][1]の作成、データ型はuint8,*0は配列を0番目にするため
for i in range(256):
    Y[i][0] = 255 * pow(float(i)/255, 1.0 / 1.5)        #ガンマ変換:f(x)=255(x/255)^(1/r)よりr=1.5

#ルックアップテーブル変換
img_dst4 = cv2.LUT(img_src, Y)

cv2.imshow('src', img_src)
cv2.imshow('g_correction', img_dst4)

cv2.imwrite(file_dst, img_dst4)

cv2.waitKey(0)
cv2.destoryAllWindow()

#g_correctionは画像の輝度や色彩を補正する際に使う
#np.ones((2, 3))
#->array([[1., 1., 1.],
#         [1., 1., 1.]])
#配列を作成し、初期値を1で埋める
#dtypeでデータ型を決定できる(初期値はfloat64)
#float64:倍精度浮動小数点型(符号1, 指数11, 仮数52)
#uint8  :符号なし8ビット整数型
Exemple #4
0
'''
#----------------16寫入一般文字
import cv2 as cv
import numpy as np
img = np.zeros((512, 512, 3), np.uint8)
#zeros...為黑色
font = cv.FONT_HERSHEY_SIMPLEX
#font這裡為字體輸入
cv.putText(img, 'openCV', (10, 350), font, 4, (255, 255, 255), 2, cv.LINE_AA)
#(img,寫入的文字'openCV',座標(10,350),字體font,字大小4,
#顏色(255,255,255)==這三個數字為白色,
#線條粗細(thickness)2,反鋸齒(盡量平滑)(linetype)cv.LINE_AA)

cv.imshow('image', img)
cv.waitKey()
cv.destoryAllWindow()

#--------------------------17寫入文字 並列出全部字體
import cv2 as cv
import numpy as np
img = np.zeros((512, 512, 3), np.uint8)
img.fill(64)  #填入數值#從(0,0,0) 填入數值變(64,64,64)
#RGB數值都一樣的時候為 灰色 (64,64,64)
text = 'opencv for python'
cv.putText(img,text,(10,40),cv.FONT_HERSHEY_SIMPLEX,\
           1,(0,255,255),1,cv.LINE_AA)
cv.putText(img,text,(10,80),cv.FONT_HERSHEY_PLAIN,\
           1,(0,255,255),2,cv.LINE_AA)
cv.putText(img,text,(10,120),cv.FONT_HERSHEY_DUPLEX,\
           1,(0,255,255),1,cv.LINE_AA)
cv.putText(img,text,(10,160),cv.FONT_HERSHEY_COMPLEX,\