We are using the following Python script combined with OpenCV to record video of salmon migration in order to estimate total fish passage,
import cv2
import numpy as np
import time
import datetime
import pathlib
import imutils
import os
import shutil
import socket
szPlacename = 'Yukon River'
iCaptureDuration = 600
iFramesPerSec = 3
szFramesPerSec = str(iFramesPerSec)
cap = cv2.VideoCapture(0)
iSleepDuration = 0
iFrameWidth = 1024
iFrameHeight = 768
szFrameWidth = str(iFrameWidth)
szFrameHeight = str(iFrameHeight)
szComputerName = socket.gethostname()
iTotal, iUsed, iFree = shutil.disk_usage("/")
iPercent = 100 * iUsed / iTotal
iPercent = round(iPercent, 1)
szPercent = str(iPercent)+"%"
font = cv2.FONT_HERSHEY_COMPLEX_SMALL
if (cap.isOpened() == False):
print("Unable to read camera feed")
pathlib.Path(('C:\LZ\')+szPlacename+"-"+(datetime.datetime.now().strftime("%Y%m%d"))).mkdir(parents=True, exist_ok=True)
out = cv2.VideoWriter('C:\LZ\'+szPlacename+"-"+datetime.datetime.now().strftime("%Y%m%d")+'/'+datetime.datetime.now().strftime("%Y%m%d%H%M%S") + " "+ szPlacename + '_StarLink.avi',cv2.VideoWriter_fourcc('m','j','p','g'),iFramesPerSec, (iFrameWidth,iFrameHeight))
iPrev = 0
iStartTime = time.time()
while( int(time.time() - iStartTime) < iCaptureDuration ):
#start fps
iTimeElapsed = time.time() - iPrev
while(iTimeElapsed > 1./iFramesPerSec):
ret, frame = cap.read()
if not ret:
break
if iTimeElapsed > 1./iFramesPerSec:
iPrev = time.time()
szDateTime = str(datetime.datetime.now())
szDateTime = szDateTime[0:22]
if ret==True:
frame = imutils.resize(frame, width=iFrameWidth)
frame = cv2.putText(frame,"Laptop: "+szComputerName+", HD used= "+szPercent+", FPS= "+szFramesPerSec+", Size(px)= "+szFrameWidth+"x"+szFrameHeight,(10,90),font, 1,(0,255,255),2,cv2.LINE_8)
frame = cv2.putText(frame,"Location: "+szPlacename +", Time: "+ szDateTime,(10,120),font, 1,(0, 255, 255),2,cv2.LINE_8)
out.write(frame)
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
cap.release()
out.release()
cv2.destroyAllWindows()
Migration occurs during the day and at night. We have installed underwater lights to facilitate counting after dark.
Here are links to video captured at dusk as well as after dark,
Dusk: https://youtu.be/EtMkmfISS48
Dark: https://youtu.be/FHELMpw_mpQ
Question: Are there other aspects of OpenCV that could be utilized that would improve low light image capture?
The camera is a USB ELP 1080P Low Light (0.01 lux) 30fps H.264 IMX323 camera for industrial machine vision purchased from AliExpress.
Thanks in advance…