0

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.

4
  • 7
    More of a comment on the physics than anything else - you would get better results with a red LED 660nm or near IR one 780nm. Blue light scatters significantly more than red light in a turbid medium. It should give you better target contrast and a lot less backscatter. Some cameras can be subverted to do time exposures at a lower FPS but for salmon that may not be useful. Putting a faster lens on the camera would also help. Check that your camera doesn't have an IR filter inside before investing in IR LEDs. Some cameras offer 2x2 binning of pixels which might help you a bit. Commented Aug 12, 2024 at 17:29
  • 2
    If you cannot see the fish well, then any algorithm in 2D image processing will have a hard time, also. You might improve the lighting as recommended by Martin Brown above and put more lights in the water. Also possibly train an AI approach to recognize the fish under the different lighting situations that you have. Commented Aug 12, 2024 at 18:06
  • It might be more efficient to use a fishfinder?.. Commented Aug 12, 2024 at 18:17
  • 1
    get more light. not an opencv issue. Commented Aug 12, 2024 at 20:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.