Package: rakali
Rakali (Version 0.0.11)Rakali is a imaging library and video camera tool-set. It provides a number of
camera primitives to help with calibrating mono and stereo camera rigs, image
processing and object detection. It also includes a number of pre-built tools to
help with that.Rakali makes use of many other imaging libraries and frameworks and is also intended
to be used as a pedagogical resource for those.Pia RavenariNamed after Hydromys chrysogaster, the Australian OtterProvided toolsRakali ships with a number of tools that assists working with mono and stereo
video cameras.ToolPurposerakali-find-ipcamerasDiscover IP cameras on the local LANrakali-viewView live video streamrakali-view-stereoView live stereo video streamrakali-find-chessboardsFind calibration images in live video feedrakali-find-chessboards-stereoFind calibration images in live stereo video feedrakali-calibrate-pinholeCalibrate a standard lens camerarakali-calibrate-fisheyeCalibrate a fish-eyed lens camerarakali-calibrate-fisheye-stereoCalibrate a fish-eyed stereo rigrakali-undistort-pinholeCorrect standard lens camera live video feedrakali-undistort-fisheyeCorrect fish-eye camera live video feedrakali-undistort-fisheye-imageCorrect image provided by calibrated fish-eye camerarakali-split-stereo-feedSplit recorded stereo view feeds into left and right eye viewsrakaliImage processing library examplarrakali-find-ipcamerasScan local LAN for IP cameras by vendor and service.$ rakali-find-ipcameras camsUsage: rakali-find-ipcameras [OPTIONS] COMMAND [ARGS]...

  Discover IP cameras on local LAN

Options:
  --version  Show the version and exit.
  --help     Show this message and exit.

Commands:
  cams     Discover local IP cameras using vendor name
  service  Scanning for video feed servicesTo scan for cameras, do:$ rakali-find-ipcameras cams, the default is to search for axis models.Which provides a list of discovered NVR's or cameras like so:Scanning 10.41.212.0/24 for axis cameras or NVRs
['10.41.212.135', '10.41.212.147']rakali-viewView live video feed from IP and USB cameras. IP cameras and NVR's that
broadcast their services over mDNS can be discovered usingrakali-find-ipcameras.$ rakali-view --helpUsage: rakali-view [OPTIONS]

Options:
  --version          Show the version and exit.
  -s, --source TEXT  Video source, can be local USB cam (0|1|2..) or IP cam rtsp URL or file  [default: http://axis-
                     lab/axis-cgi/mjpg/video.cgi?&camera=2]
  --help             Show this message and exit.A simple single stream video player.rakali-find-chessboardsFind checkerboard images in video feed for calibration purposes.rakali-find-chessboardswill look for a chessboard patterns in the frame flow
and save each frame containing a chessboard for batch processing during camera
calibration.$ rakali-find-chessboards --helpUsage:rakali-find-chessboards[OPTIONS]Testeachframeinthestreamforthepresenceofachess-boardpattern.Iffound,savetotheoutputfolder

Options:--versionShowtheversionandexit.-s,--sourceTEXTVideosource,canbelocalUSBcam(0|1|2..)orIPcamrtspURLorfile[default:http://axis-lab/axis-cgi/mjpg/video.cgi?&camera=1]-o,--output-folderTEXTOutputfolderforimagescontainingachessboard[default:~/rakali/chessboards/]--chessboard-rowsINTEGERChessboardrows[default:9]--chessboard-columnsINTEGERChessboardcolumns[default:6]--helpShowthismessageandexit.The process will drop calibration frames in the target folder like these:$ tree ~/rakali/chessboards
/home/thys/rakali/chessboards
├── 00000.jpg
├── 00001.jpg
├── 00002.jpg
├── 00003.jpgrakali-find-chessboards-stereoFind checkerboard images in stereo video feed for calibration purposes. It
operates in the same way asrakali-find-chessboardsbut produces pairs of
frames.rakali-find-chessboards-stereo --helpUsage: rakali-find-chessboards-stereo [OPTIONS]

  Find chessboard calibration images in both frames of the stereo pair

Options:
  --version                     Show the version and exit.
  -l, --left-eye TEXT           Left eye, can be local USB cam (0|1|2..) or IP cam rtsp URL or file  [default:
                                http://axis-lab/axis-cgi/mjpg/video.cgi?&camera=1]
  -r, --right-eye TEXT          Right eye, can be local USB cam (0|1|2..) or IP cam rtsp URL or file  [default:
                                http://axis-lab/axis-cgi/mjpg/video.cgi?&camera=2]
  -o, --output-folder TEXT      Fetch image from URL  [default: ~/rakali/stereo/chessboards/]
  --chessboard-rows INTEGER     Chessboard rows  [default: 9]
  --chessboard-columns INTEGER  Chessboard columns  [default: 6]
  --help                        Show this message and exit.$tree~/rakali/stereo/chessboards
/home/thys/rakali/stereo/chessboards
├──left_00000.jpg
├──left_00001.jpg
├──left_00002.jpg
├──right_00000.jpg
├──right_00001.jpg
├──right_00002.jpgrakali-calibrate-pinholeCalibrate a video camera with a pinhole lens$ rakali-calibrate-pinhole --helpUsage: rakali-calibrate-pinhole [OPTIONS]

  Calibrate pinhole camera using chessboard frames captured earlier.

Options:
  --version                     Show the version and exit.
  -i, --input-folder TEXT       Folder where chessboard images are stored  [default: ~/rakali/chessboards/]
  --image-points-file TEXT      Corner points data  [default: image_points.npz]
  --calibration-file TEXT       Camera calibration data  [default: pinhole_calibration.npz]
  --chessboard-rows INTEGER     Chessboard rows  [default: 9]
  --chessboard-columns INTEGER  Chessboard columns  [default: 6]
  --square-size FLOAT           Chessboard square size in m  [default: 0.023]
  --salt INTEGER                Seed value for random picking of calibration images from a large set  [default: 888]
  --pick-size INTEGER           Size of image set to use for calibration, picked from available set  [default: 50]
  --help                        Show this message and exit.rakali-calibrate-fisheyeCalibrate a video camera with a fish-eye lens using chessboard calibration
images captured usingrakali-find-chessboards.$ rakali-calibrate-fisheye --helpUsage: rakali-calibrate-fisheye [OPTIONS]

  Calibrate fish-eye camera using chessboard frames captured earlier.

Options:
  --version                     Show the version and exit.
  -i, --input-folder TEXT       Folder where chessboard images are stored  [default: ~/rakali/chessboards/]
  --image-points-file TEXT      Corner points data  [default: image_points.npz]
  --calibration-file TEXT       Camera calibration data  [default: fisheye_calibration.npz]
  --chessboard-rows INTEGER     Chessboard rows  [default: 9]
  --chessboard-columns INTEGER  Chessboard columns  [default: 6]
  --square-size FLOAT           Chessboard square size in m  [default: 0.023]
  --salt INTEGER                Seed value for random picking of calibration images from a large set  [default: 888]
  --pick-size INTEGER           Size of image set to use for calibration, picked from available set  [default: 50]
  --cid TEXT                    Calibration ID to associate a calibration file with a device  [default: fisheye]
  --help                        Show this message and exit.Executing$ rakali-calibrate-fisheyeresults:$ rakali-calibrate-fisheye
Loading previously computed image points from image_points.npz
Calibrating on 50 objects...
INFO:rakali.camera.fisheye:Saving fisheye calibration data to fisheye_calibration.npz
DIM=(1920, 1080)
K=np.array([[558.6421513930135, 0.0, 977.0871045041308], [0.0, 559.5579191046008, 493.7827965652395], [0.0, 0.0, 1.0]])
D=np.array([[-0.018316232894576033], [0.002931049514785237], [-0.0022823146847841804], [0.00014813140230995043]])
Calibration error: 0.8771782112164381The resulting calibration file contains the K and D matrixes and some metadata{"D":[[-0.018316232894576033],[0.002931049514785237],[-0.0022823146847841804],[0.00014813140230995043]],"K":[[558.6421513930135,0.0,977.0871045041308],[0.0,559.5579191046008,493.7827965652395],[0.0,0.0,1.0]],"cid":"fisheye","error":0.8771782112164381,"image_size":[1920,1080],"pick_size":50,"salt":888,"time":1553647761.7596939}rakali-calibrate-fisheye-stereorakali-calibrate-fisheye-stereouses a fixed set of previously captured chessboard images to calibrate a
fisheye stereo camera rig. The calculated parameters are saved in a calibration file for use in image
rectification.$ rakali-calibrate-fisheye-stereo --helpUsage:rakali-calibrate-fisheye-stereo[OPTIONS]Calibratefish-eyestereocamerarigusingchessboardframescapturedearlier.

Options:--versionShowtheversionandexit.-i,--input-folderTEXTFolderwherechessboardimagesarestored[default:~/rakali/stereo/chessboards/]--left-image-points-fileTEXTLeftCornerpointsdata[default:left_image_points.json]--right-image-points-fileTEXTRightCornerpointsdata[default:right_image_points.json]--calibration-fileTEXTStereoCameracalibrationdata[default:fisheye_stereo_calibration.json]--chessboard-rowsINTEGERChessboardrows[default:9]--chessboard-columnsINTEGERChessboardcolumns[default:6]--square-sizeFLOATChessboardsquaresizeinm[default:0.023]--saltINTEGERSeedvalueforrandompickingofcalibrationimagesfromalargeset[default:888]--pick-sizeINTEGERSizeofimagesettouseforcalibration,pickedfromavailableset[default:50]--cidTEXTCalibrationIDtoassociateacalibrationfilewithadevice[default:fisheye]--prefilter/--no-prefilterPrefilterimages[default:True]--helpShowthismessageandexit.....
Image/home/thys/rakali/stereo/chessboards/left_00088.jpgOK
Image/home/thys/rakali/stereo/chessboards/left_00058.jpgOK
Image/home/thys/rakali/stereo/chessboards/right_00238.jpgOK
Image/home/thys/rakali/stereo/chessboards/left_00122.jpgOK
Loadingpreviouslycomputedimagepointsfromleft_image_points.json
Calibratingon50objects...
Loadingpreviouslycomputedimagepointsfromright_image_points.json
Calibratingon50objects...
CalibrateFisheyeStereocamerausingpre-calibratedvaluesDIM=(1920,1080)leftcalibrationK=np.array([[552.7233750094179,0.0,948.2959591699556],[0.0,554.6925141069631,548.3575557665413],[0.0,0.0,1.0]])D=np.array([[-0.05136306776237411],[0.0959513318929465],[-0.09081590588179426],[0.028414418435600244]])Calibrationerror:0.5128009096414867
rightcalibrationK=np.array([[552.7233750094177,0.0,948.2959591699567],[0.0,554.6925141069636,548.3575557665405],[0.0,0.0,1.0]])D=np.array([[-0.051363067762376646],[0.09595133189294996],[-0.09081590588179408],[0.028414418435599085]])Calibrationerror:0.46991635076102695rakali-undistort-pinholeCorrect video feed from calibrated standard pinhole camera$ rakali-undistort-pinhole --helpUsage: rakali-undistort-pinhole [OPTIONS]

  Undistort live feed from pinhole model type camera

Options:
  --version                Show the version and exit.
  -s, --source TEXT        Video source, can be local USB cam (0|1|2..) or IP cam rtsp URL or file  [default:
                           http://axis-lab/axis-cgi/mjpg/video.cgi?&camera=1]
  --calibration-file TEXT  Camera calibration data  [default: pinhole_calibration.npz]
  --help                   Show this message and exit.rakali-undistort-fisheyeCorrect video feed from calibrated fisheye-lens camera$ rakali-undistort-fisheye --helpUsage: rakali-undistort-fisheye [OPTIONS]

  Undistort live video feed from fish-eye lens camera

Options:
  --version                Show the version and exit.
  -s, --source TEXT        Video source, can be local USB cam (0|1|2..) or IP cam rtsp URL or file  [default:
                           http://axis-lab/axis-cgi/mjpg/video.cgi?&camera=1]
  --calibration-file PATH  Camera calibration data  [default: fisheye_calibration.npz]
  -b, --balance FLOAT      Balance value 0.0 ~30% pixel loss, 1.0 no loss  [default: 1.0]
  --help                   Show this message and exit.$ rakali-undistort-fisheye$ rakali-undistort-fisheye -b 0.5$ rakali-undistort-fisheye -b 0rakali-undistort-fisheye-image$ rakali-undistort-fisheye-image --helpUsage:rakali-undistort-fisheye-image[OPTIONS]IMAGE_PATHRectifyaimagetakenwithafish-eyelenscamerausingcalibrationparameters

Options:--versionShowtheversionandexit.--calibration-filePATHCameracalibrationdata[default:fisheye_calibration.json;required]-b,--balanceFLOATBalancevalue0.0~30%pixelloss,1.0noloss[default:1.0]-s,--scaleFLOATScaleimage[default:0.5]--helpShowthismessageandexit.$ rakali-undistort-fisheye-image ~/rakali/chessboards/00000.jpgrakali-view-stereoView live feed from stereo camera rig$ rakali-view-stereo --helpUsage: rakali-view-stereo [OPTIONS]

Options:
  --version             Show the version and exit.
  -l, --left-eye TEXT   Left eye, can be local USB cam (0|1|2..) or IP cam rtsp URL or file  [default: http://axis-
                        lab/axis-cgi/mjpg/video.cgi?&camera=1]
  -r, --right-eye TEXT  Right eye, can be local USB cam (0|1|2..) or IP cam rtsp URL or file  [default: http://axis-
                        lab/axis-cgi/mjpg/video.cgi?&camera=2]
  --help                Show this message and exit.rakali-split-stereo-feedSplit source stereo recording into left and right camera views$ rakali-split-stereo-feed --helpUsage: rakali-split-stereo-feed [OPTIONS]

  Split source stereo recording into left and right camera views

Options:
  --version              Show the version and exit.
  -s, --source TEXT      Stereo video source file to split  [default: in.avi]
  -l, --left-name TEXT   Left camera video name  [default: left_eye_out.avi]
  -r, --right-name TEXT  Right camera video name  [default: right_eye_out.avi]
  --fps FLOAT            Frames per second rate for output file  [default: 12.5]
  --help                 Show this message and exit.rakaliRakali ships with a small demo app that exercises the library image processing
functionality.$rakali--help
Usage:rakali[OPTIONS]COMMAND[ARGS]...RakaliimagetoolsProvideeitherainputfileorainputURLforimagesourceOptions:--versionShowtheversionandexit.-i,--input-filePATHUsefile-u,--input-urlTEXTFetchimagefromURL-o,--output-filePATHOutputfile[default:out.jpg]--helpShowthismessageandexit.

Commands:resizeResizetheinputimagepreservingaspectratio,favoringwidthrotateRotatetheinputimagerotate-boundedRotatetheinputimage,keepingboundinplaceskeletonizeSkeletonizetheinputimageLibrary usageLibrary documentation generation is a work in progress...Load and show image from filefromrakaliimportImage
Image.from_file('rakali.jpg').show()Load, annotate, and show image#! /usr/bin/env pythonfromrakaliimportImage
img:Image=Image.from_file('rakali.jpg')img.add_text(labels=['Rakali','Hydromys chrysogaster'])img.show()img.write('rakali-text.jpg')Canny#! /usr/bin/env python"""Cannyfy Live USB video stream"""fromrakaliimportVideoPlayer,VideoStream,VideoWriter
fromrakali.video.fpsimportcost
fromrakali.videoimportgo
fromrakali.annotateimportadd_frame_labels,colors
importimutils
importlogging

logging.basicConfig(level=logging.DEBUG)@cost
defcanny(mat):img=imutils.auto_canny(image=mat,sigma=0.3)img=add_frame_labels(frame=img,labels=[f'canny cost: {canny.cost:6.3f}ms'],color=colors.get('WHITE'),)returnimgstream=VideoStream(src=0)player=VideoPlayer()writer=VideoWriter(size=stream.get_wh_size(),file_name='canny.avi')withstream,player,writer:whilego():frame=canny(stream.read())writer.write(frame)player.show(frame)InstallRakali is essentially a OpenCV shim. Because some parts of Rakali depends on OpenCV CUDA being available. The
'python-opencv' lib on PyPi is not marked as a dependency. You need to install either that yourself, or use
your own pre-compiled OpenCV CUDA. Arch Linux has opencv-cuda in AUR, so install that:$ yay -S opencv-cudaWhile you are at it also installtensorflow-opt-cuda:# pacman -S tensorflow-opt-cudapypiRakali is in pypi:$ pip install rakaliManual installClone or download this repo and in your virtualenv do:$ pip install .