PureBasic Interface to OpenCV

Developed or developing a new product in PureBasic? Tell the world about it.
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: PureBasic Interface to OpenCV ---- 05/16/14 06:20 PM

Post by applePi »

thats too much good example, thank you JHPJHP, i say to the casual watchers to press enter to change the scene and space to load another smaller picture, space again to blend. right click to save.
the library are too advanced for me but i can use it through the PB examples without looking at the details. i should read some books about it.
i suggest an alpha channel example such as changing the surrounding area like the area flood filled to alpha channel, transparent.
or such as this
Image
User avatar
JHPJHP
Addict
Addict
Posts: 2251
Joined: Sat Oct 09, 2010 3:47 am

Re: PureBasic Interface to OpenCV ---- 05/17/14 10:00 AM

Post by JHPJHP »

Hi applePi,

Thank you for your comments. Concerning a transparency example...

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

Updated:
- added 1 example
-- cv_transparent.pb: flood fill a color area to transparency, applied when the image has been saved to a PNG file
- added 2 images

NB*: Instructions on how to use the examples are included as tooltips located within each example, viewable when the mouse pointer is over the main window.

Cheers!
Last edited by JHPJHP on Sun May 18, 2014 8:18 am, edited 2 times in total.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: PureBasic Interface to OpenCV ---- 05/17/14 10:00 AM

Post by applePi »

thank you JHPJHP, the transparency example works nicely. i have noticed that the images must be 24 BPP else if it is 8 BPP it will result in an error. but thats not problem at all.
thanks
User avatar
JHPJHP
Addict
Addict
Posts: 2251
Joined: Sat Oct 09, 2010 3:47 am

Re: PureBasic Interface to OpenCV ---- 05/18/14 03:15 PM

Post by JHPJHP »

Hi applePi,

You're welcome, and thank you for letting me know about the issue with 8 BPP images.

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

Updated:
- updated 1 example
-- cv_transparent.pb: flood fill a color area to transparency, applied when the image has been saved to a PNG file

Example now supports single channel images, including a couple additional related effects.
- [ B ] KEY: Filter for black pixels.
- [ I ] KEY: Invert the image.

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

Updated:
- updated 1 example
-- cv_transparent.pb: flood fill a color area to transparency, applied when the image has been saved to a PNG file

Example now supports two ways to set transparency:
- hold down mouse and drag: applied to the highlighted area
- single click: applied to the color area

Cheers!
Last edited by JHPJHP on Mon May 19, 2014 1:11 am, edited 1 time in total.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
AAT
Enthusiast
Enthusiast
Posts: 259
Joined: Sun Jun 15, 2008 3:13 am
Location: Russia

Re: PureBasic Interface to OpenCV ---- 05/18/14 03:15 AM

Post by AAT »

Hi, JHPJHP!
Your recent examples surprised me and struck my imagination!
Thanks for your hard work and sharing.

Good luck!
User avatar
JHPJHP
Addict
Addict
Posts: 2251
Joined: Sat Oct 09, 2010 3:47 am

Re: PureBasic Interface to OpenCV ---- 05/19/14 07:00 AM

Post by JHPJHP »

Hi AAT,

It's good to hear from you, and I'm glad you like the new examples.

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

Updated:
- updated 1 example
-- cv_transparent.pb: flood fill a color area to transparency, applied when the image has been saved to a PNG file

Example now supports another way to set transparency:
- [ S ] KEY: Toggle select mode
-- outline an object you want preserved (default)
-- highlight an area you want removed / select a color area you want removed

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

Updated:
- updated 1 example
-- cv_transparent.pb: flood fill a color area to transparency, applied when the image has been saved to a PNG file

Example now supports another way to set transparency:
- [ F ] KEY: Flip image/transparency
-- this can be useful if you want to use the highlight removal feature to include the area

NB*: Fixed an issue where in some cases if there was more then one outlined area, the resulting cuts may not have matched the outlines.

Cheers!
Last edited by JHPJHP on Tue May 27, 2014 8:52 pm, edited 1 time in total.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
User avatar
JHPJHP
Addict
Addict
Posts: 2251
Joined: Sat Oct 09, 2010 3:47 am

Re: PureBasic Interface to OpenCV ---- 05/20/14 12:00 PM

Post by JHPJHP »

Updated:
- renamed 1 example
-- cv_poisson_blending.pb to cv_poisson_blending_1.pb
- added 4 examples
-- cv_poisson_blending_2.pb: using a mixed Poisson blending algorithm, two images are blended together
-- cv_poisson_blending_3.pb: using a Poisson blending algorithm, a monochrome transfer is achieved between two images
-- cv_poisson_blending_4.pb: using a Poisson blending algorithm, a localized color change is achieved
-- cv_poisson_blending_5.pb: using a Poisson blending algorithm, a localized illumination change is achieved
- added 20 images

The new examples use a slightly modified version of the code found in cv_poisson_blending_1.pb, but significantly expand the ability to blend images.

The following images show a user defined cutout of a jet pasted onto a landscape, and the completed mixed blending process; for the most part I've opted to use full images in the current examples, in order to demonstrate them without requiring user interaction.

NB*: Refer to the example cv_transparent.pb for script hosting a user defined cutout process.

Image

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
User avatar
JHPJHP
Addict
Addict
Posts: 2251
Joined: Sat Oct 09, 2010 3:47 am

Re: PureBasic Interface to OpenCV ---- 05/23/14 12:00 PM

Post by JHPJHP »

Updated:
- updated 1 example
-- cv_transparent.pb: flood fill a color area to transparency, applied when the image has been saved to a PNG file
- added 1 example
-- cv_calculate.pb: add, subtract, multiply, or divide every array element of an image

Added a couple track bars to cv_transparent.pb to better control flood filling.

cv_calculate.pb demonstrates one technique to manipulate image, mat, etc. array elements.

Update also includes bug fixes and improvement to various examples.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
AAT
Enthusiast
Enthusiast
Posts: 259
Joined: Sun Jun 15, 2008 3:13 am
Location: Russia

Re: PureBasic Interface to OpenCV ---- 05/23/14 12:00 PM

Post by AAT »

Hi.

This is an example of the image gamma correction. The source is here

Code: Select all

IncludeFile "includes/cv_functions.pbi"

Procedure GammaCorrection(*srcImg, *dstImg, GammaValue.d)
  i.l
  Dim lut.b(256)
  
  For i = 0 To 255
    lut(i) = Pow(i/255.0, 1.0/GammaValue) * 255.0
  Next i  
  *lut = cvCreateMatHeader(1, 256, CV_MAKETYPE(#CV_8U, 1))    
  cvSetData(*lut, @lut(), 0) 
  cvLUT(*srcImg, *dstImg, *lut)
EndProcedure

ImageFile$ = "Girl.png"

*src.IplImage = cvLoadImage(ImageFile$, #CV_LOAD_IMAGE_ANYDEPTH | #CV_LOAD_IMAGE_ANYCOLOR)
If *src
  *dst1.IplImage = cvCreateImage(*src\width, *src\height, #IPL_DEPTH_8U, *src\nChannels)  
  *dst2.IplImage = cvCreateImage(*src\width, *src\height, #IPL_DEPTH_8U, *src\nChannels)
	
	cvShowImage ("src", *src)	
	
	nGamma.d = 3.5
	GammaCorrection(*src, *dst1, nGamma)
	cvShowImage ("dst1", *dst1) 	
	
        nGamma = 0.7	
	GammaCorrection(*src, *dst2, nGamma)
	cvShowImage ("dst2", *dst2) 
		
	cvWaitKey (0)
	
	cvDestroyAllWindows()
	cvReleaseImage(@src)
	cvReleaseImage(@dst1)
	cvReleaseImage(@dst2)
EndIf
Test image:
Image
User avatar
JHPJHP
Addict
Addict
Posts: 2251
Joined: Sat Oct 09, 2010 3:47 am

Re: PureBasic Interface to OpenCV ---- 05/24/14 03:40 AM

Post by JHPJHP »

Hi AAT,

Nice example, I've added it to the package.

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

Updated:
- added 1 example (contributed by AAT)
-- cv_gamma.pb: Gamma Correction: The relationship between a pixels numerical value and its actual luminance
- added 2 images

The two included images demonstrate one of the uses for Gamma Correction, that of revealing objects otherwise obscured by low brightness.

Thanks AAT.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
AAT
Enthusiast
Enthusiast
Posts: 259
Joined: Sun Jun 15, 2008 3:13 am
Location: Russia

Re: PureBasic Interface to OpenCV ---- 05/24/14 03:40 AM

Post by AAT »

Thanks JHPJHP, your examples are more perfect and effective.
I think, you are a perfectionist in the positive sense and it is very good. :D

Good luck!
User avatar
grapy
User
User
Posts: 31
Joined: Sat Sep 06, 2003 9:32 am

Re: PureBasic Interface to OpenCV ---- 05/24/14 03:40 AM

Post by grapy »

Hello,

I found out that when i use

Code: Select all

*mat.CvMat = cvEncodeImage(extension, *image, @params)
more then once it doesn't release the memory.
I tried

Code: Select all

cvReleaseMat(*mat)
but it doesn't work.
Can anyone help?
I hope :mrgreen:
AAT
Enthusiast
Enthusiast
Posts: 259
Joined: Sun Jun 15, 2008 3:13 am
Location: Russia

Re: PureBasic Interface to OpenCV ---- 05/24/14 03:40 AM

Post by AAT »

Hi, grapy,
can you give us more info about:
- OS version
- OpenCV version
- CRuntime Libraries version
and the executable example of your code?
--------------------------------------------
Update

i think that your problem is in wrong calling of function

Code: Select all

cvReleaseMat(*mat)
It have to be

Code: Select all

cvReleaseMat(@*mat)
see p.83 in "manual.pdf"

My test work fine.

Code: Select all

IncludeFile "includes/cv_functions.pbi"

*image.IplImage = cvLoadImage("D:\flower.JPG", #CV_LOAD_IMAGE_ANYDEPTH | #CV_LOAD_IMAGE_ANYCOLOR)
cvShowImage ("Image", *image) 
For i=0 To 5
  *mat.CvMat = cvEncodeImage(".JPG", *image, 0)
  Debug ("Encoded")
  cvWaitKey(0)
  cvReleaseMat(@*mat)
  Debug ("Released")  
  cvWaitKey(0)  
Next
Good luck!
User avatar
grapy
User
User
Posts: 31
Joined: Sat Sep 06, 2003 9:32 am

Re: PureBasic Interface to OpenCV ---- 05/24/14 03:40 AM

Post by grapy »

Hi, AAT,
sorry for less information, but you got it. Great!!!
Code works now. Thank you very much.
Greetings, Grapy
User avatar
JHPJHP
Addict
Addict
Posts: 2251
Joined: Sat Oct 09, 2010 3:47 am

Re: PureBasic Interface to OpenCV ---- 05/27/14 02:20 PM

Post by JHPJHP »

Hi AAT,

Thank you for the compliment, but I think I'm more OCD then perfectionist. :)

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

Updated:
- renamed 9 examples
-- cv_boundingrectangle.pb to cv_bounding_rectangle.pb
-- cv_cam_fallingballs.pb to cv_cam_falling_balls.pb
-- cv_cam_pbdatabase.pb to cv_cam_pb_database.pb
-- cv_imagedots.pb to cv_image_dots.pb
-- cv_pbfont.pb to cv_pb_font.pb
-- cv_pbimage_1.pb to cv_pb_image_1.pb
-- cv_pbimage_2.pb to cv_pb_image_2.pb
-- cv_solvemaze.pb to cv_solve_maze.pb
-- le_nearestneighbor.pb to le_nearest_neighbor.pb
- added 1 example
-- cv_pencil_sketch.pb: simulate a color / black & white pencil sketch from an image
- added 2 images

The new example is based on code from the C++ blending script mentioned in a previous post.

Note:
- press the Spacebar to switch between color / black & white
- to increase the pencil effect increase the parameter: iterations (found in the Procedure: PencilSketch)
- to increase or decrease the pencil effect change the parameter: shade (found in the Procedure: OpenCV)

Cheers!

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
Locked