opencv 비디오의 색상 범위에 대해 thresholding입니다. 목표는 학업 프로젝트를위한 의료용 초음파 비디오에서 컬러 흐름 도플러 모드 (속도 정보)에서 B 모드 (흑백, 위치는 있지만 속도는 아님)를 분리하는 것입니다. 저는 초음파 장비 (밝은 파란색 [opencv hue 90]에서 노란색 [opencv hue 35]까지)에 의해 전달 된 컬러 스케일에서 재구성 한 HSV 색조 범위를 기준으로 임계 값을 시도했습니다. 불행히도 결과는 좋지 않습니다. thresholding에서 실수를 했습니까? 아니면 원하는 결과를 얻을 수있는 또 다른 방법이 있습니까? 아래는 내 코드와 내 결과의 프레임 예제입니다. 색조 만 구성 요소에 따라 opencv 비디오의 색상 임계 값 설정
#!/usr/bin/env python
# -*- coding: utf-8 -*-
##IMPORTS
import cv2.cv as cv
import numpy as np
##VARIABLES
#colors
doppler_hues=np.concatenate([np.arange(90,181),np.arange(0,36)])
##MAIN
#start video stream analysis
frames = raw_input('Please enter video file:')
if not frames:
print "This program requires a file as input!"
sys.exit(1)
# first, create the necessary windows
cv.NamedWindow ('image', cv.CV_WINDOW_AUTOSIZE)
cv.NamedWindow ('original', cv.CV_WINDOW_AUTOSIZE)
#File capture
vidFile = cv.CaptureFromFile(frames)
nFrames = int( cv.GetCaptureProperty(vidFile, cv.CV_CAP_PROP_FRAME_COUNT))
fps = cv.GetCaptureProperty(vidFile, cv.CV_CAP_PROP_FPS)
waitPerFrameInMillisec = int(1/fps * 1000/1)
for f in xrange(nFrames):
#frame capture
frame = cv.QueryFrame(vidFile)
# create the images we need
original = cv.CreateImage (cv.GetSize (frame), 8, 3)
cv.Copy(frame,original)
image = cv.CreateImage (cv.GetSize (frame), 8, 3)
cv.CvtColor(frame, image, cv.CV_BGR2HSV)
image2 = cv.CreateImage (cv.GetSize (frame), 8, 3)
if not frame:
break
#Replace pixel colors
image=np.asarray(image[:,:])
hue=np.resize(image,(480,640,1))
hue[np.where((np.not_equal(hue,doppler_hues)).all(axis=2))]=[0]
hue2=np.resize(hue,(480,640,3))
image[np.where((hue2==[0,0,0]).all(axis=2))]=[0,0,0]
image=cv.fromarray(image[:,:])
cv.CvtColor(image, image2, cv.CV_HSV2BGR)
#show the image
cv.ShowImage("image", image2)
cv.ShowImage("original", original)
#quit command ESC
if cv.WaitKey(waitPerFrameInMillisec)==27:
break
else:
cv.WaitKey(waitPerFrameInMillisec) % 0x100
cv.DestroyAllWindows()
고맙습니다! 귀하의 답변이 내 프로그램을 많이 가속화했으며, 잘 작동합니다! – Raoul
반갑습니다. –