libOpenCV Windows/Linux 32/64-bit

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
Dll_User
Posts: 1
Joined: Mar 14, 2020 7:39

Re: libOpenCV Windows/Linux 32/64-bit

Postby Dll_User » Mar 14, 2020 8:08

Hello,

this is my first post hier - so when i make a fault please write me. most off the time i use Freebasic to make DLLs for Funktions i offen need. And now i see this with opencv here. Great Job !!!. Off cours i must check it out because in python it is very easy to implement the funktions.
i tried the examples and as far i can see they work great. Then i wanted to try Template Matching like this in the Link:
https://docs.opencv.org/2.4/doc/tutoria ... ching.html
the soure if from intern Camera extern Camera Video or picture to import works but wenn i try dies funktions:
cvSetImageROI(picture,rect) OpenCV Error: Assertion failed
cvMatchTemplate(picture,template,resultpic,CV_TM_CCORR_NORMED) OpenCV Error: Assertion failed
cvMinMaxLoc (not Tested)
Im quit sure i only make a little fault and i don't find it.

Here the Examplecode i tested:

Code: Select all

#include "opencv.bi"

dim Groesse as cvSize
dim Rechteck as cvRect

DIM min_loc AS cvPoint
DIM max_loc AS cvPoint
DIM min_val AS DOUBLE
DIM max_val AS DOUBLE

dim as IplImage ptr MatchBild
dim as IplImage ptr MatchTemplet
dim as IplImage ptr MatchResult
dim as IplImage ptr MatchMask

MatchBild = cvLoadImage("Source.PNG") ' This could be replaced with frame of camera
MatchTemplet = cvLoadImage("Template.PNG")

Rechteck = cv_Rect(1,2,10,20)' Dateiformat long x y w h
print rechteck.x
print rechteck.y
print rechteck.width
print rechteck.height


'cvGetSize
Groesse = cvGetSize(MatchBild)
print Groesse.width
print Groesse.height

'cvGetImageROI
Rechteck = cvGetImageROI(MatchBild)
print rechteck.x
print rechteck.y
print rechteck.width
print rechteck.height

'cvSetImaeROI (OpenCV ERROR)
cvSetImageROI(MatchBild,Rechteck)

'cvMatchTemplate (OpenCV ERROR)
cvMatchTemplate(MatchBild,MatchTemplet,MatchResult, CV_TM_CCORR_NORMED)
'cvMinMaxLoc (untested)
cvMinMaxLoc(MatchResult, @min_val, @max_val, @min_loc,@max_loc,MatchMask )

print min_val
print max_val
print min_loc
print max_loc


When somebody new my fault it would be very nice to knew it. And Thanks for Reading it. When there are question or something isn't well explained please write.
AND a big THANKS on the writer off the OPENCV binding.
yzfwsf
Posts: 7
Joined: Apr 05, 2020 11:34

Re: libOpenCV Windows/Linux 32/64-bit

Postby yzfwsf » Apr 06, 2020 9:48

Which version of OpenCV is implemented?Tks.
MrSwiss
Posts: 3455
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: libOpenCV Windows/Linux 32/64-bit

Postby MrSwiss » Apr 06, 2020 12:40

yzfwsf wrote:Which version of OpenCV is implemented?Tks.

This sort of information is typically found in the threads first (opening) post ...
yzfwsf
Posts: 7
Joined: Apr 05, 2020 11:34

Re: libOpenCV Windows/Linux 32/64-bit

Postby yzfwsf » Apr 06, 2020 13:18

yzfwsf wrote:Which version of OpenCV is implemented?Tks.

Stupid question, version is 2.4.13

Code: Select all

 Dim sudoku(8, 8) As Long
   Dim undistorted As IplImage Ptr, src As IplImage Ptr, res As IplImage Ptr
   src = cvLoadImage("sudoku.png", CV_LOAD_IMAGE_GRAYSCALE)     
   res = cvCreateImage(cvGetSize(src), IPL_DEPTH_8U, 1)

When cvcreateimage is called, the program crashes in Windows XP.


@D.J.Peters
Would you please provide a text recognition example, such as identifying numbers on Sudoku picture. Tks.
D.J.Peters
Posts: 8023
Joined: May 28, 2005 3:28
Contact:

Re: libOpenCV Windows/Linux 32/64-bit

Postby D.J.Peters » Apr 07, 2020 23:42

yzfwsf wrote:When cvCreateImage() is called, the program crashes in Windows XP.
I got a crash on 64-bit Windows 10 also :-)
instead of creating a new image from another (a copy)
try to clone it ! (should work see my tests above)
res = cvCloneImage(src)
yzfwsf wrote:Would you please provide a text recognition example, such as identifying numbers on Sudoku picture. Tks.
No I self don't use OpenCV !

Joshy
BasicCoder2
Posts: 3525
Joined: Jan 01, 2009 7:03

Re: libOpenCV Windows/Linux 32/64-bit

Postby BasicCoder2 » Apr 08, 2020 0:16

@yzfwsf,
It seems easy to do with Python using opencv and tesseract. Not sure how to translate that to a FreeBASIC version.
https://towardsdatascience.com/read-tex ... 2ede074cac

Code: Select all

img = cv2.imread('bitcoin.jpg')
text = pytesseract.image_to_string(img)
print(text)

The subject of image to text has come up before.
viewtopic.php?t=25866

It seems these days you don't have to do any low level programming, instead all you need to do is find the right library and know how to interface it to your language of choice. Joshy has made a lot libraries available to the FreeBasic programmer with opencv being the latest.
yzfwsf
Posts: 7
Joined: Apr 05, 2020 11:34

Re: libOpenCV Windows/Linux 32/64-bit

Postby yzfwsf » Apr 08, 2020 1:54

D.J.Peters wrote:I got a crash on 64-bit Windows 10 also :-)
instead of creating a new image from another (a copy)
try to clone it ! (should work see my tests above)
res = cvCloneImage(src)

Code: Select all

Dim undistorted As IplImage Ptr, src As IplImage Ptr, res As IplImage Ptr
   src = cvLoadImage("sudoku.png", CV_LOAD_IMAGE_GRAYSCALE)
   Dim cvsz As cvSize
   cvsz = cvGetSize(src)   
   res = cvCreateImage(cvsz, IPL_DEPTH_8U, 1)
   cvSmooth(src, res,CV_GAUSSIAN,11,11)

I divided cvcreateimage into two steps, which worked well, but progam crashed when I called cvsmooth.
Tourist Trap
Posts: 2853
Joined: Jun 02, 2015 16:24

Re: libOpenCV Windows/Linux 32/64-bit

Postby Tourist Trap » May 06, 2020 10:07

Thank you D.J. Peters, you did a big work. Now yes, there is still the need to learn the lib.

I have to say that I had to dig up a little around to understand that there is 2 implementations of OpenCV, one for C++, and one for C. And their stuff differs it seems (functions names and so on). For who, like me that had not the right documentation, of course it's all about the C interface here.


yzfwsf wrote:

Code: Select all

 Dim sudoku(8, 8) As Long
   Dim undistorted As IplImage Ptr, src As IplImage Ptr, res As IplImage Ptr
   src = cvLoadImage("sudoku.png", CV_LOAD_IMAGE_GRAYSCALE)     
   res = cvCreateImage(cvGetSize(src), IPL_DEPTH_8U, 1)


What if you don't use the parameter in cvLoadImage? Theorically you should test if your pointed image is not null. In my first test, I had to remove any second argument to get a valid pointer.
As for obtaining a grayscale image, maybe you can do it after having loaded everything?

My first test was:

Code: Select all

#include "opencv.bi"

cvNamedWindow("win") : cvResizeWindow("win",640,480)

dim as IplImage Ptr img = cvLoadImage("TM.jpg")
? img

cvShowImage("winMain", img)

' loop with 10Hz while [ESC] not pressed
while cvWaitKey(1000/10)<>27
    '   
wend

cvDestroyWindow("win")
Tourist Trap
Posts: 2853
Joined: Jun 02, 2015 16:24

Re: libOpenCV Windows/Linux 32/64-bit

Postby Tourist Trap » May 06, 2020 12:34

Hi again, just to be sure, the constructors of MAT datatype are not implemented, are they?
https://docs.opencv.org/ref/2.4/d3/d63/ ... _1Mat.html

From what I can guess the MAT datatype is defined here in this file:
opencv_core_types.bi

Roughtly here is what I found concerning the class definition:
Here:

Code: Select all

type CvMat
    as long type
    as long step
  ' for internal use only
    as long ptr refcount
    as long hdr_refcount
    as _CvMatData data
    as long rows
    as long cols
end type
'....
' constructor: No data is allocated internally!!!
' (Use together with cvCreateData, or use cvCreateMat instead to get a matrix with allocated data):
' renamed: cvMat
function cv_Mat( rows as long, cols as long, _type as long, _data as any ptr CV_DEFAULT(NULL) ) as CvMat
  dim as CvMat m=any
  _type = CV_MAT_TYPE(_type)
  m.type = CV_MAT_MAGIC_VAL or CV_MAT_CONT_FLAG or _type
  m.cols = cols
  m.rows = rows
  m.step = m.cols*CV_ELEM_SIZE(_type)
  m.data._ptr = _data
  m.refcount = NULL
  m.hdr_refcount = 0
  return m
end function


There is 2 issues so far. Compared to what is found there: https://docs.opencv.org/ref/2.4/d3/d63/ ... _1Mat.html, there are many missing constructors. Unless they are defined elsewhere. And this datatype can not be extended by hand just by trying to write the missing stuff for at least one reason, it contains a field named "type" which makes fbc refusing any addition of a new function. Renaming this field would potentially lead endless trouble, so I'm stuck right at this point.

Has anyone a good advice to reach the feature I want? Or did I miss something?

What I need is the constructor that converts IplImage to Mat. For now I get only:
error 24: Invalid data types, at parameter 1 (rows) of CV_MAT() in 'dim as CvMat m = cv_mat(img)
Needed, I suppose, a way to define this:
§ Mat() [17/24]
cv::Mat::Mat ( const IplImage * img, bool copyData = false )
converts old-style IplImage to the new matrix; the data is not copied by default

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 5 guests