It is currently Fri Jul 19, 2019 7:36 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 818 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6 ... 55  Next
Author Message
 Post subject: Re: OpenCV (v2)
PostPosted: Fri Nov 29, 2013 4:51 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Oct 09, 2010 3:47 am
Posts: 1572
Hi AAT,

Very nice addition...

You might have missed a previous update where I fixed a problem that you pointed out earlier. The following prevents 1 channel images from crashing; I will shortly incorporate the new example into the fold.
Code:
*resize = cvCreateImage(iWidth, iHeight, #IPL_DEPTH_8U, *image\nChannels)
...
If *image\nChannels = 1
  *gray = cvCloneImage(*image)
Else
  *gray = cvCreateImage(*image\width, *image\height, #IPL_DEPTH_8U, 1)
  cvCvtColor(*image, *gray, #CV_BGR2GRAY, 1)
EndIf

-------------------------------------------------------

A new function and a new example have been added (cv_contours_1b.pb) - both contributed by AAT.
- the example is an extension of cv_contours_1a.pb (formally cv_contours.pb)
-- a filter has been applied so that "noise" is excluded
Quote:
This example scans an image for contours building each contour into an array of points. It then applies the data to a blank matrices using predefined filters, creating a "drawn" version of the image (filled or outlined).

_________________

I will be unreachable from the forum for an indefinite period; downloads moved to My PureBasic Stuff.
_________________


Last edited by JHPJHP on Sat Nov 30, 2013 1:36 am, edited 3 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: OpenCV (v2)
PostPosted: Fri Nov 29, 2013 6:03 pm 
Offline
Enthusiast
Enthusiast

Joined: Sun Jun 15, 2008 3:13 am
Posts: 236
Location: Russia
JHPJHP wrote:
The following prevents 1 channel images from crashing;

I have tested monocrome images with 1 bit, 4 bit, 8 bit per pixel (saved with MS Paint from colour 24 bit image).
There is no difference: 1 bit - crash, others - work fine.


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenCV (v2)
PostPosted: Fri Nov 29, 2013 8:49 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Oct 09, 2010 3:47 am
Posts: 1572
Hi AAT,

I'm using Channel to describe the success / failure of the image because that's where it failed in the code. When I created / cloned an image based on the Structure's nChannels return value my tests passed. Without the update some images caused a program error (Windows XP) or crashed the program (Windows 7).

NB*: I don't think bit-depth is the problem as indicated by the included files.
- [ with change.pb ] & [ without change.pb ]: folder \Pass\ (image files work)
- [ with change.pb ]: folder \Fail\ (image files work)
- [ without change.pb ]: folder \Fail\ (image files don't work)

Thanks!

_________________

I will be unreachable from the forum for an indefinite period; downloads moved to My PureBasic Stuff.
_________________


Last edited by JHPJHP on Sat Nov 30, 2013 10:06 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: OpenCV (v2)
PostPosted: Sat Nov 30, 2013 6:26 am 
Offline
Addict
Addict
User avatar

Joined: Sat Oct 09, 2010 3:47 am
Posts: 1572
New Functions and a new example (cv_contours_1c.pb) have been added.
- adds a Bounding Rectangle to all the points returned from the cvFindContours Function

There is still an issue with using cvMinAreaRect2, but the CvContour Structure has a CvRect parameter readily available.
- the limitation is that there is no Angle parameter compared with CvBox2D which allows for a Rotated-Rectangle
-- a workaround would only require a little math and the cvPolyLine Function (see example: cv_shapes.pb)

Cheers!

_________________

I will be unreachable from the forum for an indefinite period; downloads moved to My PureBasic Stuff.
_________________


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenCV (v2)
PostPosted: Sat Nov 30, 2013 10:00 am 
Offline
Enthusiast
Enthusiast

Joined: Sun Jun 15, 2008 3:13 am
Posts: 236
Location: Russia
Hi, JHPJHP

JHPJHP wrote:

I have tested your programm "with change.pb", it works fine.
I found a copy-paste error in my code, so it works too.

JHPJHP wrote:
There is still an issue with using cvMinAreaRect2, but the CvContour Structure has a CvRect parameter readily available...

Thank you, but CvRect is bounding rectangle.
I need a rotated rectangle (center & angle parameters) i.e in cvMinAreaRect2 function...
Perhaps, moments can help me.

Addition:
JHPJHP, you can add more functions and structure.

Code:
Structure CvMoments
  m00.d
  m10.d
  m01.d
  m20.d
  m11.d
  m02.d
  m30.d
  m21.d
  m12.d
  m03.d
  mu20.d
  mu11.d
  mu02.d
  mu30.d
  mu21.d
  mu12.d
  mu03.d
  inv_sqrt_m00.d
EndStructure

ImportC "opencv_core247.lib"
  cvAnd(*src1Array, *src2Array, *dstArray, *maskArray)
  cvXor(*src1Array, *src2Array, *dstArray, *maskArray)
  cvNot(*srcArr, *dstArr)
EndImport

ImportC "opencv_imgproc247.lib"
   cvMoments(*arr, *moments, binary.i)
EndImport


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenCV (v2)
PostPosted: Sat Nov 30, 2013 8:33 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Oct 09, 2010 3:47 am
Posts: 1572
Hi AAT,

Sorry, it must have been the way I worded it, I didn't need you to test it for me - I knew it worked, I only made it available as a test / comparison for you to fix your code, demonstrating my results.
Quote:
I have tested your programm "with change.pb", it works fine.

Either I misunderstood your requirements, or you missed this in my last post:
Quote:
a workaround would only require a little math and the cvPolyLine Function

- I'll update the package later with a new example, including the Structure & Functions from your post (thanks!)
- you said rotated, not rotated and bound (too include bounded requires a little more math)
- I noticed a small caveat - if the lines are aliasing, use the context menu to open the image a second time (something still too figure out)
Code:
Dim pts.CvPoint(4)
npts = ArraySize(pts())
angle.d = 0.45

For rtnCount = 1 To nContours
  area.d = cvContourArea(*contours, 0, $3fffffff, 0)

  If area >= 35
    cvDrawContours(*contour, *contours, 255, 155, 0, 0, 155, 255, 0, 0, -1, 1, #CV_AA, 0, 0)
    x = Round(*contours\rect\x + *contours\rect\width / 2, #PB_Round_Up)
    y = Round(*contours\rect\y + *contours\rect\height / 2, #PB_Round_Up)    width = *contours\rect\width
    height = *contours\rect\height
    pts(0)\x = Round(x + (width / 2) * Cos(angle) - (height / 2) * Sin(angle), #PB_Round_Nearest)
    pts(0)\y = Round(y + (height / 2) * Cos(angle) + (width / 2) * Sin(angle), #PB_Round_Nearest)
    pts(1)\x = Round(x - (width / 2) * Cos(angle) - (height / 2) * Sin(angle), #PB_Round_Nearest)
    pts(1)\y = Round(y + (height / 2) * Cos(angle) - (width / 2) * Sin(angle), #PB_Round_Nearest)
    pts(2)\x = Round(x - (width / 2) * Cos(angle) + (height / 2) * Sin(angle), #PB_Round_Nearest)
    pts(2)\y = Round(y - (height / 2) * Cos(angle) - (width / 2) * Sin(angle), #PB_Round_Nearest)
    pts(3)\x = Round(x + (width / 2) * Cos(angle) + (height / 2) * Sin(angle), #PB_Round_Nearest)
    pts(3)\y = Round(y - (height / 2) * Cos(angle) + (width / 2) * Sin(angle), #PB_Round_Nearest)
    cvPolyLine(*contour, pts(), @npts, 1, #True, 0, 0, 255, 0, 1, #CV_AA, #Null)
    cvRectangleR(*contour, *contours\rect\x, *contours\rect\y, *contours\rect\width, *contours\rect\height, 0, 255, 255, 0, 1, #CV_AA, #Null)
  EndIf
  *contours = *contours\h_next
Next

_________________

I will be unreachable from the forum for an indefinite period; downloads moved to My PureBasic Stuff.
_________________


Last edited by JHPJHP on Sun Dec 01, 2013 4:40 am, edited 3 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: OpenCV (v2)
PostPosted: Sun Dec 01, 2013 4:41 am 
Offline
Addict
Addict
User avatar

Joined: Sat Oct 09, 2010 3:47 am
Posts: 1572
Added Constants, Structures, and Functions (jointly contributed by AAT).

Combined examples cv_contours_1a.pb & cv_contours_1b.pb, renamed example cv_contours_1c.pb to cv_contours_1b.pb, added a new example: cv_contours_1c.pb.
- the Contour Filter contributed by AAT now incorporated into all Contour examples.

The new example draws a Rotated-Rectangle (by degree) around the contour array of an image.
- see previous post for more information

Cheers!

_________________

I will be unreachable from the forum for an indefinite period; downloads moved to My PureBasic Stuff.
_________________


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenCV (v2)
PostPosted: Tue Dec 03, 2013 6:14 am 
Offline
Addict
Addict
User avatar

Joined: Sat Oct 09, 2010 3:47 am
Posts: 1572
Added Constants, Structures, Macros, Functions (jointly contributed by AAT)

Renamed / modified example: cv_contours_1c.pb to cv_contours_1x.pb (experimental / jointly contributed by AAT).

2 new examples (contributed by AAT)
- cv_contours_1c.pb: applies a bounding circle around the contour array of an image
- cv_sequence.pb: creates a sequence array of circles and applies a bounding circle around them

_________________

I will be unreachable from the forum for an indefinite period; downloads moved to My PureBasic Stuff.
_________________


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenCV (v2)
PostPosted: Tue Dec 03, 2013 7:39 am 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3598
Location: Berlin, Germany
Many thanks for your ongoing work!

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenCV (v2)
PostPosted: Tue Dec 03, 2013 8:10 am 
Offline
User
User

Joined: Thu Mar 30, 2006 11:14 am
Posts: 92
Ditto.

I've really enjoyed playing with this, appreciate the work & continued updates, thanks.

One thing worth watching though, is that you release any generated images when processing in a loop (any projects utilizing a webcam for example) or you end up with quite a severe memory leak.

On the pb_effects examples:
Adding:
Code:
If *gray : cvReleaseImage(@*gray) : EndIf

to the beginning of the Repeat:Until section does the job.


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenCV (v2)
PostPosted: Tue Dec 03, 2013 9:32 am 
Offline
Addict
Addict
User avatar

Joined: Sat Oct 09, 2010 3:47 am
Posts: 1572
Thanks guys.

------------------

Renamed examples that utilize the webcam with _cam.

Updated pb_effects_1_cam.pb & pb_effects_2_cam.pb due to a memory leak (thanks pjay).

------------------

I would also like to mention the amount of work AAT has put into this project, and is continuing to put into it.
- most of his work, and our correspondence is outside of this forum, so it may not have been completely obvious

Cheers!

_________________

I will be unreachable from the forum for an indefinite period; downloads moved to My PureBasic Stuff.
_________________


Last edited by JHPJHP on Tue Dec 03, 2013 2:20 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: OpenCV (v2)
PostPosted: Tue Dec 03, 2013 2:13 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Oct 09, 2010 3:47 am
Posts: 1572
Added 1 Structure and 1 Function, updated 1 example: cv_contours_1x.pb, and added 1 example: cv_contours_2.pb.

The new example finds the convex hull of a point set.

_________________

I will be unreachable from the forum for an indefinite period; downloads moved to My PureBasic Stuff.
_________________


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenCV (v2)
PostPosted: Wed Dec 04, 2013 3:35 am 
Offline
Enthusiast
Enthusiast

Joined: Mon Aug 19, 2013 3:28 pm
Posts: 256
This is AMAZING, JHP & AAT! Keep up the GREAT work!

However, is there an easy way to implement sound into the AVI videos? A video is no good without sound!

Thank You!


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenCV (v2)
PostPosted: Thu Dec 05, 2013 4:29 am 
Offline
Addict
Addict
User avatar

Joined: Sat Oct 09, 2010 3:47 am
Posts: 1572
Added Constants, Structures, Function, and 3 examples.

In the first example: cv_contours_3a.pb: Contours & Approximating Polygonal Curves Image Effect - small circles are drawn at each Contour (x/y) point with precision set to 5.

In the second example: cv_contours_3b.pb: Contours & Approximating Polygonal Curves Image Effect with Bounding Rectangle - precision is set to 0 returning the most points; extracted from the list of points are coordinates used to draw a bounding rectangle around the image.

How this is different from other examples is the ability to capture the return values (x/y points), which can range from hundreds to just a few depending on the precision setting.

In the third example: cv_contours_4.pb: Contours & Convexity Defects Image Effect - small circles are draw at each Convexity Defect. A part of the script that deserves some attention is the cvCvtSeqToArray function; is converts the information stored in the CvSeq Structure returned from CvConvexityDefect to an array storing various (x/y) points.

NB*: In every update I do, there may be other small changes to examples or includes that are not mentioned, so it's best to replace the entire package.

Cheers!

_________________

I will be unreachable from the forum for an indefinite period; downloads moved to My PureBasic Stuff.
_________________


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenCV (v2)
PostPosted: Mon Dec 09, 2013 1:16 am 
Offline
Addict
Addict
User avatar

Joined: Sat Oct 09, 2010 3:47 am
Posts: 1572
Added Functions, renamed, deleted, replaced, added examples (too many changes to remember).
-- cv_cam_logo.pb: adds an image to top left corner of webcam interface (inspired by work AAT was doing with cvAnd & cvXor)
-- cv_contours_4.pb: used exclusively for certain types of squares, rectangles
-- cv_ROI.pb: takes a region from an image and displays it as its own image
-- pb_cam_effects_3.pb: showcases the cvAnd & cvXor Functions (contributed by AAT)

Cheers!

_________________

I will be unreachable from the forum for an indefinite period; downloads moved to My PureBasic Stuff.
_________________


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 818 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6 ... 55  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye