Python+OpenCVでのチェック、Pythonシート検査設定用プログラムの解像度を3264x2448に変更したものを作成して動作させてみたが、どうもおかしい。

トリミング位置の赤線表示の右側と下側が切れてしまう。

解像度を3264x2448に設定できていないと思い、次の様なプログラムを作成し、設定確認できるようにした。(確認中はいろいろいじってる。)

import numpy as np
import cv2
import time
import asyncio # プログラム全体を止めない非同期待ち時間指定用、asyncio.run(asyncio.sleep(4)) で4秒待ち

# print(cv2.getBuildInformation())
#cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*"YUYV"))
#cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('Y','U','Y','V'))
#cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*"MJPG"))
#cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M','J','P','G'))
#cap.set(6, cv2.VideoWriter_fourcc('M','J','P','G'))

def decode_fourcc(v):
        v = int(v)
        return "".join([chr((v >> 8 * i) & 0xFF) for i in range(4)])

cap = cv2.VideoCapture(0)

asyncio.run(asyncio.sleep(2))
# frame_list = [(3264, 2448), (2592, 1944), (2048, 1536), (1920, 1080), (1600, 1200)]
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 3264)
asyncio.run(asyncio.sleep(2))
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 2448)
asyncio.run(asyncio.sleep(2))

width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
print("width   = " + str(width))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
print("height  = " + str(height))
fps    = int(cap.get(cv2.CAP_PROP_FPS))
print("FPS     = " + str(fps))
fourcc = cap.get(cv2.CAP_PROP_FOURCC)
print("FOURCC  = " + str(fourcc))
#fourcc = decode_fourcc(cap.get(cv2.CAP_PROP_FOURCC))
#fourcc = fourcc.to_bytes(4, 'little').decode('utf-8')
#print("FOURCC  = " + str(fourcc))
#fourcc_code = cv2.VideoWriter_fourcc(*'MJPG')
#print(fourcc_code)
#fourcc_code = cv2.VideoWriter_fourcc(*'YUY2')
#print(fourcc_code)
cv2.VideoWriter.fourcc(*'MJPG')
fourcc = cap.get(cv2.CAP_PROP_FOURCC)
print("FOURCC  = " + str(fourcc))
print(fourcc)
fps    = int(cap.get(cv2.CAP_PROP_FPS))
print("FPS     = " + str(fps))

cv2.VideoWriter.fourcc(*'YUY2')
fourcc = cap.get(cv2.CAP_PROP_FOURCC)
print("FOURCC  = " + str(fourcc))
print(fourcc)
fps    = int(cap.get(cv2.CAP_PROP_FPS))
print("FPS     = " + str(fps))

format = int(cap.get(cv2.CAP_PROP_FORMAT))
print("FORMAT  = " + str(format))
mode = int(cap.get(cv2.CAP_PROP_MODE))
print("MODE    = " + str(mode))
rgb = int(cap.get(cv2.CAP_PROP_CONVERT_RGB))
print("CV_RGB  = " + str(rgb))
bright = int(cap.get(cv2.CAP_PROP_BRIGHTNESS))
print("BRIGHT  = " + str(bright))
contrast = int(cap.get(cv2.CAP_PROP_CONTRAST))
print("CONTRAST= " + str(contrast))
saturation = int(cap.get(cv2.CAP_PROP_SATURATION))
print("SATURAT = " + str(saturation))
hue = int(cap.get(cv2.CAP_PROP_HUE))
print("HUE     = " + str(hue))
gain = int(cap.get(cv2.CAP_PROP_GAIN))
print("GAIN    = " + str(gain))
exposure = int(cap.get(cv2.CAP_PROP_EXPOSURE))
print("EXPOSURE= " + str(exposure))
wbtemperature = int(cap.get(cv2.CAP_PROP_WB_TEMPERATURE))
print("WB_TEMP = " + str(wbtemperature))
gamma = int(cap.get(cv2.CAP_PROP_GAMMA))
print("GAMMA   = " + str(gamma))
focus = int(cap.get(cv2.CAP_PROP_FOCUS))
print("FOCUS   = " + str(focus))
pan = int(cap.get(cv2.CAP_PROP_PAN))
print("PAN     = " + str(pan))
tilt = int(cap.get(cv2.CAP_PROP_TILT))
print("TILT    = " + str(tilt))
roll = int(cap.get(cv2.CAP_PROP_ROLL))
print("ROLL    = " + str(roll))
iris = int(cap.get(cv2.CAP_PROP_IRIS))
print("IRIS    = " + str(iris))
autoexp = int(cap.get(cv2.CAP_PROP_AUTO_EXPOSURE))
print("AUTO_EXP= " + str(autoexp))
autofcs = int(cap.get(cv2.CAP_PROP_AUTOFOCUS))
print("AUTO_FCS= " + str(autofcs))
autowb = int(cap.get(cv2.CAP_PROP_AUTO_WB))
print("AUTO_WB = " + str(autowb))
xiautowb = int(cap.get(cv2.CAP_PROP_XI_AUTO_WB))
print("XIAUTOWB= " + str(xiautowb))
xiaeag = int(cap.get(cv2.CAP_PROP_XI_AEAG))
print("XI_AEAG = " + str(xiaeag))
xiaemaxlim = int(cap.get(cv2.CAP_PROP_XI_AE_MAX_LIMIT))
print("XIAEMXLT= " + str(xiaemaxlim))
xiagmaxlim = int(cap.get(cv2.CAP_PROP_XI_AG_MAX_LIMIT))
print("XIAGMXLT= " + str(xiagmaxlim))
temperature = int(cap.get(cv2.CAP_PROP_TEMPERATURE))
print("TEMPERAT= " + str(temperature))
trigger = int(cap.get(cv2.CAP_PROP_TRIGGER))
print("TRIGGER = " + str(trigger))
triggerdl = int(cap.get(cv2.CAP_PROP_TRIGGER_DELAY))
print("TRIGGERD= " + str(triggerdl))
settings = int(cap.get(cv2.CAP_PROP_SETTINGS))
print("SETTINGS= " + str(settings))

cap.release()

出力された数値の意味がわからないんだが、とりあえず全て表示するコード。

結果は次の通り。

width   = 2048

height  = 1536

FPS     = 3

FOURCC  = 22.0

FOURCC  = 22.0

22.0

FPS     = 3

FOURCC  = 22.0

22.0

FPS     = 3

FORMAT  = -1

MODE    = 1

CV_RGB  = 1

BRIGHT  = 0

CONTRAST= 32

SATURAT = 32

HUE     = 0

GAIN    = -1

EXPOSURE= -5

WB_TEMP = -1

GAMMA   = 150

FOCUS   = 0

PAN     = -1

TILT    = -1

ROLL    = -1

IRIS    = -1

AUTO_EXP= 0

AUTO_FCS= 0

AUTO_WB = -1

XIAUTOWB= -1

XI_AEAG = -1

XIAEMXLT= -1

XIAGMXLT= -1

TEMPERAT= 4600

TRIGGER = 1

TRIGGERD= 1

SETTINGS= 1

解像度が2048x1536になっている。

2592x1944に設定しようとしても、2048x1536になる。

FOURCCは22.0で、変更しようとしても変更が効いていないのか22.0のままで変化無し。


しばらく格闘しても訳が分からないので、オートフォーカスを切り、マニュアルフォーカス操作をやってみることにする。

コメント

このブログの人気の投稿