Sei sulla pagina 1di 4

ForOpenCVinstallation,youcanfollowinstructionsat

https://help.ubuntu.com/community/OpenCV.However,therearenumerousinstructionsabout
installingOpenCVonUbuntu.Youcanfollowanyinstallationmethodaslongasitinstallscorrect
OpenCVlibrariesandotherdependencies.

1.ThefollowingisthesummaryhowIdidit.Theprocedurespresentedhereareoptimisedfor1)
diskspacerequiredforbuilding2)buildingtimeonBBBbysacrificing1)correctpythonbinding
2)skipbuildingallthetestsandperformancetests3)skipmostofadvancedfeatureslikegpu
support(wedontneedthisatallforBBB).

ThefollowingprocedureassumesthatyoualreadyfinishedUbuntuinstallationonyourBBB,you
havevalidinternetconnection,andyouhavecorrectdate/timeonBBB.

WARNING:Thisinstallationwilltakeatleastacoupleofhours.Makesureyouhaveyouhave
reliableinternetconnectionandpowersupply.

2.Downloadscriptfileinyourhomefolder(oranyotherfolderyouwant)forinstallation:

$wgethttp://users.monash.edu.au/~hchung/TRC3000/dependencies.sh
$wget
http://users.monash.edu.au/~hchung/TRC3000/get_latest_version_download_file.sh
$wgethttp://users.monash.edu.au/~hchung/TRC3000/opencv_install.sh

3.Makethemexecutable:

$chmod+x*.sh

3.Makesureyoureconnectedtointernetandyoursystemtimeiscorrect.Thenstartinstallation
by

$./opencv_install.sh

Notethatthiswilltakemorethantwohours.Somakesureyouareconnectedtoreliableinternet
andpower.

Itshouldendwithsomethinglike

OpenCV2.4.9readytobeused

4.Nowitstimetotesttheinstallation.

Makeafolderforcompilingthistestcode,forexample/home/ubuntu/coding/opencvtest/
andgothethefolder
Createtest.cusingnanoandtypethefollowingcodein:

#include<opencv2/highgui/highgui.hpp>

intmain()
{
IplImage*img=cvLoadImage("./cat.jpg",CV_LOAD_IMAGE_COLOR)
cvNamedWindow("opencvtest",CV_WINDOW_AUTOSIZE)
cvShowImage("opencvtest",img)
cvWaitKey(0)
cvReleaseImage(&img)
return0
}

Compilethecodeusingthefollowingcommand:

$gccggdb`pkgconfigcflagsopencv`o`basenametest.c.c`
test.c`pkgconfiglibsopencv`

Copytheimageforthis(dontforgetabout.attheend!)

$cp/home/ubuntu/OpenCV/opencv2.4.9/samples/c/cat.jpg.

Executetheexecutableby

$./test

thenyoushouldbeabletoseethiscutecatonthescreenofthehostcomputer

5.Asthefinaltestofinstallation,letsseehowwecancaptureanimagefromthewebcam
(LogitechC110).

ConnectthewebcamtoBBBtherearetwowaystodothis.Oneisjustsimply
shutdownthesystem,disconnectWifidongle,pluginthewebcam,thenpowerupagain.
TheotheroneistouseaUSBhub.ItishighlyrecommendedtouseaUSBhubatleast
fordesktopdevelopment.
Onceyouconnectthewebcam,youshouldbeabletoseeitfromusbdevicelist:

ubuntu@arm:~$lsusb
Bus001Device002:ID046d:0829Logitech,Inc.
Bus001Device001:ID1d6b:0002LinuxFoundation2.0roothub
Bus002Device001:ID1d6b:0002LinuxFoundation2.0roothub

Alsoitshouldappearas/dev/video0(trytolsof/devfolder)
Ifitdoesntappearonthedevicelist,thenrebootandtryagain.
Ifeverythingsfine,thencreatetest_cam.casfollowsusingnano

#include"cv.h"
#include"highgui.h"
#include<stdio.h>

//ASimpleCameraCapture
intmain(){

//parametersforjpegsaving
intparam[3]={CV_IMWRITE_JPEG_QUALITY,90,0}

//openvideocapturingdevice
CvCapture*capture=cvCaptureFromCAM(CV_CAP_ANY)
if(!capture){//createerrorifthereisnoavailablecamera
fprintf(stderr,"ERROR:captureisNULL\n")
getchar()
return1
}

cvSetCaptureProperty(capture,CV_CAP_PROP_FRAME_WIDTH,1024)
cvSetCaptureProperty(capture,CV_CAP_PROP_FRAME_HEIGHT,768)

//Getoneframe
IplImage*frame=cvQueryFrame(capture)

if(!frame){
fprintf(stderr,"ERROR:frameisnull...\n")
exit(0)
}

//Displaycapturedimage
cvNamedWindow("opencvtest",CV_WINDOW_AUTOSIZE)
cvShowImage("opencvtest",frame)
cvWaitKey(0)

//savecapturedimageasajpegfile
cvSaveImage("capture.jpg",frame,param)

//Releasethecapturedevicehousekeeping
cvReleaseCapture(&capture)

return0
}

Compilethecodeusingthefollowingcommand:

$gccggdb`pkgconfigcflagsopencv`o`basenametest_cam.c.c`
test_cam.c`pkgconfiglibsopencv`

Executingitby./test_camwillcreateawindowshowingthecapturedimageandsaveit
ascapture.jpginthecurrentfolder

Potrebbero piacerti anche