Opencv

General FreeBASIC programming questions.
Post Reply
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Opencv

Post by BasicCoder2 »

Have been using opencv with other languages (Python and Processing) and wondered if anyone knows how to use it with FreeBasic ?
paul doe
Moderator
Posts: 1730
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Opencv

Post by paul doe »

Wikipedia wrote: ...
OpenCV is written in C++ and its primary interface is in C++, but it still retains a less comprehensive though extensive older C interface.
...
All of the new developments and algorithms in OpenCV are now developed in the C++ interface.
...
Which basically means that, if you want to use it in FreeBasic, you'll need to create a plain C wrapper for it (see viewtopic.php?f=3&t=28338).
JohnK_RQ
Posts: 27
Joined: Nov 25, 2019 1:50

Re: Opencv

Post by JohnK_RQ »

And see here:
viewtopic.php?t=28024
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: Opencv

Post by BasicCoder2 »

paul doe wrote: you'll need to create a plain C wrapper for it.
Unfortunately I have no idea how to create a plain C wrapper.
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: Opencv

Post by BasicCoder2 »

JohnK_RQ wrote:And see here:
viewtopic.php?t=28024
So I have asked the question before! Maybe like now I ran your example without success and gave up.
I imagined something like a opencv.bi file and an opencv.dll just as with escapi.bi and escapi.dll or k8055.bi and k8055.dll
When I run the .bas examples I get these errors and have no idea what to do about them?

Command executed:
"C:\FreeBasic\fbc.exe" "C:\Users\BasicCoder2\Downloads\QopenCV_distrib\OpenCV_test2.bas"

Compiler output:
C:\Users\BasicCoder2\Downloads\QopenCV_distrib\OpenCV_test2.bas(1) error 3: Expected End-of-Line, found '$' in '$TYPECHECK ON'
C:\Users\BasicCoder2\Downloads\QopenCV_distrib\OpenCV_test2.bas(2) error 3: Expected End-of-Line, found '$' in '$INCLUDE <rapidq2.inc>'
C:\Users\BasicCoder2\Downloads\QopenCV_distrib\OpenCV_test2.bas(3) error 3: Expected End-of-Line, found '$' in '$INCLUDE <QOpenCV.inc>'
C:\Users\BasicCoder2\Downloads\QopenCV_distrib\OpenCV_test2.bas(20) error 42: Variable not declared, CREATE in 'CREATE ImageBuffer AS QBITMAPEX'
C:\Users\BasicCoder2\Downloads\QopenCV_distrib\OpenCV_test2.bas(21) error 9: Expected expression, found '=' in 'Width = 100'
C:\Users\BasicCoder2\Downloads\QopenCV_distrib\OpenCV_test2.bas(22) error 42: Variable not declared, Height in 'Height = 100'
C:\Users\BasicCoder2\Downloads\QopenCV_distrib\OpenCV_test2.bas(23) error 42: Variable not declared, PixelFormat in 'PixelFormat = pf24bit'
C:\Users\BasicCoder2\Downloads\QopenCV_distrib\OpenCV_test2.bas(24) error 3: Expected End-of-Line, found 'CREATE' in 'END CREATE'
C:\Users\BasicCoder2\Downloads\QopenCV_distrib\OpenCV_test2.bas(25) error 146: Only valid in -lang deprecated or fblite or qb, found 'DEFLNG' in 'DEFLNG lpPixData'
C:\Users\BasicCoder2\Downloads\QopenCV_distrib\OpenCV_test2.bas(26) error 146: Only valid in -lang deprecated or fblite or qb, found 'DEFINT' in 'DEFINT myPixelDepth'
C:\Users\BasicCoder2\Downloads\QopenCV_distrib\OpenCV_test2.bas(26) error 133: Too many errors, exiting

Results:
Compilation failed

System:
FBIde: 0.4.6
fbc: FreeBASIC Compiler - Version 1.07.1 (2019-09-27), built for win32 (32bit)
OS: Windows NT 6.2 (build 9200)
paul doe
Moderator
Posts: 1730
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Opencv

Post by paul doe »

BasicCoder2 wrote:Unfortunately I have no idea how to create a plain C wrapper.
Pity.
BasicCoder2 wrote:...
When I run the .bas examples I get these errors and have no idea what to do about them?
..
That is RapidQ code (as stated by its OP). It'll need porting to FreeBasic for it to work.
JohnK_RQ
Posts: 27
Joined: Nov 25, 2019 1:50

Re: Opencv

Post by JohnK_RQ »

The main reason for the example is to show how to interface via basic language, as fb is not compatible. It is not that difficult once you get the dll code to compile. The hard work is setting up opencv distrib, which is why I included the binaries , but for xp...

I never said that it would be effortless!!!
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: Opencv

Post by BasicCoder2 »

JohnK_RQ wrote:I never said that it would be effortless!!!
It is not so much the effort as the time I would have to find to learn how make a wrapper, become an expert in RapidQ (whatever that is) and learn how to compile a dll just to use opencv. Programming is just one of my spare time interests to fit into my other family responsibilities.
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: Opencv

Post by BasicCoder2 »

Ok. Thanks for the feedback.

So essentially the answer to my question is:
Opencv is not available to the general FreeBASIC user. Best to use another language where it is available as a simple import opencv statement.

However escapi.dll and escapi.bi are available to FreeBASIC users for image capture so I will have to be content with that and writing all my own visual processing software. Now how to write some face recognition software :)

Nostalgic reminiscing:
Back in ye old days it was much simpler. My first foray into image processing was using a simple frame grabber from Scotland and a b/w video security camera which used a vidicon tube. To get color images I took three images, each through a different color filter (red, green, blue) and used the 256 color mode with a special palette. The colors were interlaced and the resulting color images looked really great. Then along came the b/w Connectix Quickcam. Lots of fun and easy to connect via the bidirectional parallel ports. You could write your own interface software using the protocol provided by Connectix. I was using TurbC and Assembler back in those days and played with making stereo depth maps using two cameras.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Opencv

Post by D.J.Peters »

I have tested a hand full of OpenCV commands with FreeBASIC successful on Windows 32/64-bit (I build an older version 2.4.13.6 with cmake)

https://docs.opencv.org/2.4.13.6/

On windows all kinds of VFV and DShow capture devices are supported (on Linux all V4L and VFL2 devices)

The problem are I self don't need it and the job must be done manually by hand (10-12 hours if you are a pro) :-(
A C/C++ file to *.bi file converter will not work it's a mix of C++,C and a bunch of complicated macros (trust me) !

Here are a list of commands (not complete) compatible with FreeBASIC
The GUI commands not listed (on Windows native UI or QT on Linux gtk or QT)

Joshy

cvCalcMatMulDeriv
cvCalibrateCamera2
cvCalibrationMatrixValues
cvCheckChessboard
cvComposeRT
cvComputeCorrespondEpilines
cvConvertPointsHomogeneous
cvCorrectMatches
cvCreatePOSITObject
cvCreateStereoBMState
cvDecomposeProjectionMatrix
cvDrawChessboardCorners
cvFindChessboardCorners
cvFindExtrinsicCameraParams2
cvFindFundamentalMat
cvFindHomography
cvFindStereoCorrespondenceBM
cvGetOptimalNewCameraMatrix
cvGetValidDisparityROI
cvInitIntrinsicParams2D
cvPOSIT
cvProjectPoints2
cvRANSACUpdateNumIters
cvRQDecomp3x3
cvReleasePOSITObject
cvReleaseStereoBMState
cvReprojectImageTo3D
cvRodrigues2
cvStereoCalibrate
cvStereoRectify
cvStereoRectifyUncalibrated
cvTriangulatePoints
cvValidateDisparity

opencv core functionalty
cvAbsDiff
cvAbsDiffS
cvAdd
cvAddS
cvAddWeighted
cvAlloc
cvAnd
cvAndS
cvAttrValue
cvAvg
cvAvgSdv
cvBackProjectPCA
cvCalcCovarMatrix
cvCalcPCA
cvCartToPolar
cvCbrt
cvChangeSeqBlock
cvCheckArr
cvCheckHardwareSupport
cvCheckTermCriteria
cvCircle
cvClearGraph
cvClearMemStorage
cvClearND
cvClearSeq
cvClearSet
cvClipLine
cvClone
cvCloneGraph
cvCloneImage
cvCloneMat
cvCloneMatND
cvCloneSparseMat
cvCmp
cvCmpS
cvColorToScalar
cvCompleteSymm
cvConvertScale
cvConvertScaleAbs
cvCopy
cvCountNonZero
cvCreateChildMemStorage
cvCreateData
cvCreateGraph
cvCreateGraphScanner
cvCreateImage
cvCreateImageHeader
cvCreateMat
cvCreateMatHeader
cvCreateMatND
cvCreateMatNDHeader
cvCreateMemStorage
cvCreateSeq
cvCreateSeqBlock
cvCreateSet
cvCreateSparseMat
cvCrossProduct
cvCvtSeqToArray
cvDCT
cvDFT
cvDet
cvDiv
cvDotProduct
cvDrawContours
cvEigenVV
cvEllipse
cvEllipse2Poly
cvEndWriteSeq
cvEndWriteStruct
cvError
cvErrorFromIppStatus
cvErrorStr
cvExp
cvFastArctan
cvFillConvexPoly
cvFillPoly
cvFindGraphEdge
cvFindGraphEdgeByPtr
cvFindType
cvFirstType
cvFlip
cvFlushSeqWriter
cvFree_
cvGEMM
cvGet1D
cvGet2D
cvGet3D
cvGetCols
cvGetDiag
cvGetDimSize
cvGetDims
cvGetElemType
cvGetErrInfo
cvGetErrMode
cvGetErrStatus
cvGetFileNode
cvGetFileNodeByName
cvGetFileNodeName
cvGetHashedKey
cvGetImage
cvGetImageCOI
cvGetImageROI
cvGetMat
cvGetModuleInfo
cvGetND
cvGetNumThreads
cvGetOptimalDFTSize
cvGetRawData
cvGetReal1D
cvGetReal2D
cvGetReal3D
cvGetRealND
cvGetRootFileNode
cvGetRows
cvGetSeqElem
cvGetSeqReaderPos
cvGetSize
cvGetSubRect
cvGetTextSize
cvGetThreadNum
cvGetTickCount
cvGetTickFrequency
cvGraphAddEdge
cvGraphAddEdgeByPtr
cvGraphAddVtx
cvGraphRemoveEdge
cvGraphRemoveEdgeByPtr
cvGraphRemoveVtx
cvGraphRemoveVtxByPtr
cvGraphVtxDegree
cvGraphVtxDegreeByPtr
cvGuiBoxReport
cvInRange
cvInRangeS
cvInitFont
cvInitImageHeader
cvInitLineIterator
cvInitMatHeader
cvInitMatNDHeader
cvInitNArrayIterator
cvInitSparseMatIterator
cvInitTreeNodeIterator
cvInsertNodeIntoTree
cvInvert
cvKMeans2
cvLUT
cvLine
cvLoad
cvLog
cvMahalanobis
cvMakeSeqHeaderForArray
cvMax
cvMaxS
cvMemStorageAlloc
cvMemStorageAllocString
cvMerge
cvMin
cvMinMaxLoc
cvMinS
cvMixChannels
cvMul
cvMulSpectrums
cvMulTransposed
cvNextGraphItem
cvNextNArraySlice
cvNextTreeNode
cvNorm
cvNormalize
cvNot
cvNulDevReport
cvOpenFileStorage
cvOr
cvOrS
cvPerspectiveTransform
cvPolarToCart
cvPolyLine
cvPow
cvPrevTreeNode
cvProjectPCA
cvPtr1D
cvPtr2D
cvPtr3D
cvPtrND
cvPutText
cvRandArr
cvRandShuffle
cvRange
cvRawDataToScalar
cvRead
cvReadRawData
cvReadRawDataSlice
cvRectangle
cvRectangleR
cvRedirectError
cvReduce
cvRegisterModule
cvRegisterType
cvRelease
cvReleaseData
cvReleaseFileStorage
cvReleaseGraphScanner
cvReleaseImage
cvReleaseImageHeader
cvReleaseMat
cvReleaseMemStorage
cvReleaseSparseMat
cvRemoveNodeFromTree
cvRepeat
cvResetImageROI
cvReshape
cvReshapeMatND
cvRestoreMemStoragePos
cvSVBkSb
cvSVD
cvSave
cvSaveMemStoragePos
cvScalarToRawData
cvScaleAdd
cvSeqElemIdx
cvSeqInsert
cvSeqInsertSlice
cvSeqInvert
cvSeqPartition
cvSeqPop
cvSeqPopFront
cvSeqPopMulti
cvSeqPush
cvSeqPushFront
cvSeqPushMulti
cvSeqRemove
cvSeqRemoveSlice
cvSeqSearch
cvSeqSlice
cvSeqSort
cvSet
cvSet1D
cvSet2D
cvSet3D
cvSetAdd
cvSetData
cvSetErrMode
cvSetErrStatus
cvSetIPLAllocators
cvSetIdentity
cvSetImageCOI
cvSetImageROI
cvSetMemoryManager
cvSetND
cvSetNumThreads
cvSetReal1D
cvSetReal2D
cvSetReal3D
cvSetRealND
cvSetRemove
cvSetSeqBlockSize
cvSetSeqReaderPos
cvSetZero
cvSliceLength
cvSolve
cvSolveCubic
cvSolvePoly
cvSort
cvSplit
cvStartAppendToSeq
cvStartNextStream
cvStartReadRawData
cvStartReadSeq
cvStartWriteSeq
cvStartWriteStruct
cvStdErrReport
cvSub
cvSubRS
cvSum
cvTrace
cvTransform
cvTranspose
cvTreeToNodeSeq
cvTypeOf
cvUnregisterType
cvUseOptimized
cvWrite
cvWriteComment
cvWriteFileNode
cvWriteInt
cvWriteRawData
cvWriteReal
cvWriteString
cvXor
cvXorS

cvCalcAffineFlowPyrLK
cvCalcGlobalOrientation
cvCalcMotionGradient
cvCalcOpticalFlowFarneback
cvCalcOpticalFlowPyrLK
cvCamShift
cvCreateKalman
cvEstimateRigidTransform
cvKalmanCorrect
cvKalmanPredict
cvMeanShift
cvReleaseKalman
cvSegmentMotion
cvUpdateMotionHistory

cvConvertImage
cvCreateCameraCapture
cvCreateFileCapture
cvCreateTrackbar
cvCreateTrackbar2
cvCreateVideoWriter
cvDecodeImage

cvWriteFrame_FFMPEG
read_InputMediaStream_FFMPEG
release_InputMediaStream_FFMPEG
release_OutputMediaStream_FFMPEG
write_OutputMediaStream_FFMPEG
cvDecodeImageM
cvDestroyAllWindows
cvDestroyWindow
cvEncodeImage
cvGetCaptureDomain
cvGetCaptureProperty
cvGetTrackbarPos
cvGetWindowHandle
cvGetWindowName
cvGetWindowProperty
cvGrabFrame
cvHaveImageReader
cvHaveImageWriter
cvInitSystem
cvLoadImage
cvLoadImageM
cvMoveWindow
cvNamedWindow
cvQueryFrame
cvReleaseCapture
cvReleaseVideoWriter
cvResizeWindow
cvRetrieveFrame
cvSaveImage
cvSetCaptureProperty
cvSetMouseCallback
cvSetOpenGlContext
cvSetOpenGlDrawCallback
cvSetPostprocessFuncWin32_
cvSetPreprocessFuncWin32_
cvSetTrackbarMax
cvSetTrackbarPos
cvSetWindowProperty
cvShowImage
cvStartWindowThread
cvUpdateWindow
cvWaitKey
cvWriteFrame

cvWatershed
cv2DRotationMatrix
cvAcc
cvAdaptiveThreshold
cvApproxChains
cvApproxPoly
cvArcLength
cvBoundingRect
cvBoxPoints
cvCalcArrBackProject
cvCalcArrBackProjectPatch
cvCalcArrHist
cvCalcBayesianProb
cvCalcEMD2
cvCalcProbDensity
cvCanny
cvCheckContourConvexity
cvClearHist
cvCompareHist
cvContourArea
cvConvertMaps
cvConvexHull2
cvConvexityDefects
cvCopyHist
cvCopyMakeBorder
cvCornerEigenValsAndVecs
cvCornerHarris
cvCornerMinEigenVal
cvCreateHist
cvCreatePyramid
cvCreateStructuringElementEx
cvCvtColor
cvDilate
cvDistTransform
cvEndFindContours
cvEqualizeHist
cvErode
cvFilter2D
cvFindContours
cvFindCornerSubPix
cvFindNextContour
cvFitEllipse2
cvFitLine
cvFloodFill
cvGetAffineTransform
cvGetCentralMoment
cvGetHuMoments
cvGetMinMaxHistValue
cvGetNormalizedCentralMoment
cvGetPerspectiveTransform
cvGetQuadrangleSubPix
cvGetRectSubPix
cvGetSpatialMoment
cvGoodFeaturesToTrack
cvHoughCircles
cvHoughLines2
cvInitUndistortMap
cvInitUndistortRectifyMap
cvIntegral
cvLaplace
cvLinearPolar
cvLogPolar
cvMakeHistHeaderForArray
cvMatchShapes
cvMatchTemplate
cvMaxRect
cvMinAreaRect2
cvMinEnclosingCircle
cvMoments
cvMorphologyEx
cvMultiplyAcc
cvNormalizeHist
cvPointPolygonTest
cvPointSeqFromMat
cvPreCornerDetect
cvPyrDown
cvPyrMeanShiftFiltering
cvPyrUp
cvReadChainPoint
cvReleaseHist
cvReleasePyramid
cvReleaseStructuringElement
cvRemap
cvResize
cvRunningAvg
cvSampleLine
cvSetHistBinRanges
cvSmooth
cvSobel
cvSquareAcc
cvStartFindContours
cvStartReadChainPoints
cvSubstituteContour
cvThreshHist
cvThreshold
cvUndistort2
cvUndistortPoints
cvWarpAffine
cvWarpPerspective

cv3dTrackerCalibrateCameras
cv3dTrackerLocateObjects
cvBGCodeBookClearStale
cvBGCodeBookDiff
cvBGCodeBookUpdate
cvCalcCovarMatrixEx
cvCalcDecompCoeff
cvCalcEMD
cvCalcEigenObjects
cvCalcImageHomography
cvCalcOpticalFlowBM
cvCalcOpticalFlowHS
cvCalcOpticalFlowLK
cvCalcPGH
cvCalcSubdivVoronoi2D
cvCalibrateCamera
cvCalibrateCamera_64d
cvChangeDetection
cvCircleAA
cvClearSubdivVoronoi2D
cvComputePerspectiveMap
cvConDensInitSampleSet
cvConDensUpdateByTime
cvContourBoundingRect
cvContourFromContourTree
cvConvexHull
cvCreate2DHMM
cvCreateBGCodeBookModel
cvCreateConDensation
cvCreateContourTree
cvCreateFGDStatModel
cvCreateGLCM
cvCreateGLCMDescriptors
cvCreateGLCMImage
cvCreateGaussianBGModel
cvCreateGaussianBGModel2
cvCreateHandMask
cvCreateKDTree
cvCreateLSH
cvCreateMemoryLSH
cvCreateObsInfo
cvCreateSpillTree
cvCreateStereoGCState
cvCreateSubdiv2D
cvDeInterlace
cvDeleteMoire
cvDynamicCorrespondMulti
cvEViterbi
cvEigenDecomposite
cvEigenProjection
cvEllipseAA
cvEndScanGraph
cvEstimateHMMStateParams
cvEstimateObsProb
cvEstimateTransProb
cvExtractSURF
cvFillImage
cvFindChessBoardCornerGuesses
cvFindDominantPoints
cvFindExtrinsicCameraParams
cvFindExtrinsicCameraParams_64d
cvFindFeatures
cvFindFeaturesBoxed
cvFindFundamentalMatrix
cvFindHandRegion
cvFindHandRegionA
cvFindNearestPoint2D
cvFindRuns
cvFindStereoCorrespondence
cvFindStereoCorrespondenceGC
cvFitEllipse
cvFitLine2D
cvFitLine3D
cvGetGLCMDescriptor
cvGetGLCMDescriptorStatistics
cvGetStarKeypoints
cvHoughLines
cvHoughLinesP
cvHoughLinesSDiv
cvImgToObs_DCT
cvInitFaceTracker
cvInitMixSegm
cvInitPerspectiveTransform
cvInitSubdivDelaunay2D
cvKMeans
cvLSHAdd
cvLSHQuery
cvLSHRemove
cvLineAA
cvLinearContorModelFromVoronoiDiagram
cvMakeAlphaScanlines
cvMakeScanlines
cvMatArray
cvMatchContourTrees
cvMean
cvMean_StdDev
cvMinAreaRect
cvMixSegmL2
cvMorphEpilinesMulti
cvPolyLineAA
cvPostWarpImage
cvPreWarpImage
cvProject3D
cvProjectPoints
cvProjectPointsSimple
cvPseudoInverse
cvPyrSegmentation
cvRand
cvRandInit
cvRandSetRange
cvRefineForegroundMaskBySegm
cvRelease2DHMM
cvReleaseBGCodeBookModel
cvReleaseBGStatModel
cvReleaseConDensation
cvReleaseFaceTracker
cvReleaseFeatureTree
cvReleaseGLCM
cvReleaseLSH
cvReleaseLinearContorModelStorage
cvReleaseObsInfo
cvReleaseStereoGCState
cvReleaseVoronoiStorage
cvRodrigues
cvSURFParams
cvSegmentFGMask
cvSegmentImage
cvSnakeImage
cvStartScanGraph
cvSubdiv2DLocate
cvSubdivDelaunay2DInsert
cvSumPixels
cvTrackFace
cvUnDistort
cvUnDistortInit
cvUnDistortOnce
cvUniformImgSegm
cvUpdateBGStatModel
cvVoronoiDiagramFromContour
cvVoronoiDiagramFromImage
cvbCartToPolar
cvbFastArctan
cvbFastExp
cvbFastLog
cvbInvSqrt
cvbRand
cvbReciprocal
cvbSqrt
cvmPerspectiveProject
icvComCoeffForLine
icvCompute3DPoint
icvComputeCoeffForStereo
icvComputeRestStereoParams
icvComputeStereoLineCoeffs
icvComputeStereoParamsForCameras
icvComputeeInfiniteProject1
icvComputeeInfiniteProject2
icvConvertPointSystem
icvConvertWarpCoordinates
icvCreateConvertMatrVect
icvCreateIsometricImage
icvDefinePointPosition
icvDrawMosaic
icvGetAngleLine
icvGetCoefForPiece
icvGetCrossDirectDirect
icvGetCrossLineDirect
icvGetCrossLines
icvGetCrossPieceDirect
icvGetCrossPiecePiece
icvGetCrossPieceVector
icvGetCrossRectDirect
icvGetCutPiece
icvGetDirectionForPoint
icvGetDistanceFromPointToDirect
icvGetMiddleAnglePoint
icvGetNormalDirect
icvGetPieceLength
icvGetPieceLength3D
icvGetQuadsTransform
icvGetQuadsTransformStruct
icvGetSymPoint3D
icvGetVect
icvProjectPointToDirect
icvProjectPointToImage
icvStereoCalibration
icvSubdiv2DCheck

cvCreateTestSet
cvRandGaussMixture
cvRandMVNormal

cvHaarDetectObjects
cvLatentSvmDetectObjects
cvLoadHaarClassifierCascade
cvLoadLatentSvmDetector
cvReleaseHaarClassifierCascade
cvReleaseLatentSvmDetector
cvRunHaarClassifierCascade
cvSetImagesForHaarClassifierCascade

cvInpaint
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Opencv

Post by D.J.Peters »

After 12 hours of work here are a preview for Windows 32/64 bit :-)
viewtopic.php?f=14&t=28361

Joshy
Post Reply