Page 17 of 60
Re: PureBasic Interface to OpenCV ---- 05/16/14 06:20 PM
Posted: Sat May 17, 2014 8:31 am
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

Re: PureBasic Interface to OpenCV ---- 05/17/14 10:00 AM
Posted: Sat May 17, 2014 3:16 pm
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!
Re: PureBasic Interface to OpenCV ---- 05/17/14 10:00 AM
Posted: Sat May 17, 2014 7:44 pm
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
Re: PureBasic Interface to OpenCV ---- 05/18/14 03:15 PM
Posted: Sun May 18, 2014 8:28 am
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!
Re: PureBasic Interface to OpenCV ---- 05/18/14 03:15 AM
Posted: Sun May 18, 2014 10:11 am
by AAT
Hi, JHPJHP!
Your recent examples surprised me and struck my imagination!
Thanks for your hard work and sharing.
Good luck!
Re: PureBasic Interface to OpenCV ---- 05/19/14 07:00 AM
Posted: Mon May 19, 2014 12:12 pm
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!
Re: PureBasic Interface to OpenCV ---- 05/20/14 12:00 PM
Posted: Wed May 21, 2014 9:09 am
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.

Re: PureBasic Interface to OpenCV ---- 05/23/14 12:00 PM
Posted: Fri May 23, 2014 5:05 pm
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.
Re: PureBasic Interface to OpenCV ---- 05/23/14 12:00 PM
Posted: Sat May 24, 2014 3:41 am
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:

Re: PureBasic Interface to OpenCV ---- 05/24/14 03:40 AM
Posted: Sat May 24, 2014 8:50 am
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.
Re: PureBasic Interface to OpenCV ---- 05/24/14 03:40 AM
Posted: Sat May 24, 2014 1:53 pm
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.
Good luck!
Re: PureBasic Interface to OpenCV ---- 05/24/14 03:40 AM
Posted: Sun May 25, 2014 12:36 am
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
but it doesn't work.
Can anyone help?
I hope

Re: PureBasic Interface to OpenCV ---- 05/24/14 03:40 AM
Posted: Sun May 25, 2014 1:21 am
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
It have to be
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!
Re: PureBasic Interface to OpenCV ---- 05/24/14 03:40 AM
Posted: Sun May 25, 2014 8:25 am
by grapy
Hi, AAT,
sorry for less information, but you got it. Great!!!
Code works now. Thank you very much.
Greetings, Grapy
Re: PureBasic Interface to OpenCV ---- 05/27/14 02:20 PM
Posted: Tue May 27, 2014 7:47 pm
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!