PureBasic Interface to OpenCV

Developed or developing a new product in PureBasic? Tell the world about it.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to OpenCV

Post by JHPJHP »

Hi dige,

The following response from OpenCV and 4K Videos best answers your question:
stackoverflow wrote:The answer to this question is an interesting one, but I think boils down to codecs or encoding of videos.

THe first video I was using was this one (although that might not be the exact download I used) which doesn't seem to play very well in VLC or OpenCV but does play fine in windows media player. I think this is because it is encoded in MPEG AAC Audio.

I then downloaded an elysium 4k trailer which is h264 encoded and seems to work fine in both VLC & OpenCV. so Hooray 4K isn't a problem overall in OpenCV!

SO I thought it might be file sizes. I paid for and downloaded a 7Gb 6 minute 4K video. This plays fine in both OpenCV & VLC with no lag even if drawing it to the screen three times. This is a .mov file and I don't currently have access to the codec (ill update this bit when I do).

So TL:DR: It's not file sizes or container types that causes issues but there does seem to be an issue with certain codecs. This is only a small exploration and there might be differing issues.
NB*: OpenCV is a computer-vision library and does not navitely process sound.
dige
Addict
Addict
Posts: 1247
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: PureBasic Interface to OpenCV

Post by dige »

Thx JHPJHP
"Daddy, I'll run faster, then it is not so far..."
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to OpenCV

Post by JHPJHP »

Hi dige,

You're most welcome.

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

First post updated; Linux now supported.
- added a Demo package with 2 examples
- tested in Ubuntu 16.04 LTS :: 64 bit

INSTALL INSTRUCTIONS:

1. Extract the OpenCV folder from the ZIP package
2. Open the /binaries/setup/ folder
3. Right-Mouse-Click selecting Open Terminal
4. Type sudo ./install_files.sh to install the required files

NB*: If you are concerned about changes to your Linux configuration, review install_files.sh before executing the above instructions.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to OpenCV

Post by JHPJHP »

First post updated:
- added a Main Linux package with 10 examples
- tested in Ubuntu 16.04 LTS :: 64 bit

Examples:
- cv_canny.pb: finds edges in an image using the Canny86 algorithm
- cv_dithering.pb: implementation of the Floyd-Steinberg dithering algorithm applied to a gray-scale image
- cv_erode_dilate.pb: erodes / dilates an image using a specific structuring element
- cv_matchtemplate.pb: compares a template against overlapped image regions; matching one face against many faces
- cv_morphology.pb: performs advanced morphological transformations using a specific structuring element
- cv_norm.pb: Using a default image, the absolute difference is calculated against a directory of images, returning the closest match
- cv_poisson_blending_1.pb: using a Poisson blending algorithm, two similarly colored images are blended together
- cv_repulsion_field.pb: each particle tries to find an optimum placement by pushing itself away from its neighbors
- cv_sepia.pb: convert a color image to sepia
- le_delaunay_voronoi.pb: iterative construction of Delaunay triangulation and Voronoi tesselation

The Main package will continue to be updated, building towards 200+ examples.
- thanks to the invaluable support provided by wilbert during the OSX conversion, only a small number of changes need to be applied to the OSX examples for them to work in Linux

In the Main package I've opted for a borderless "sticky" window.
- press the ESC key to close the window
- hold the ALT key to move the window
- context menu may include Open / Save / Exit
- tooltips provide additional information

INSTALL INSTRUCTIONS:

1. Extract the OpenCV folder from the ZIP package
2. Open the /binaries/setup/ folder
3. Right-Mouse-Click selecting Open Terminal
4. Type sudo ./install_files.sh to install the required files

NB*: If you are concerned about changes to your Linux configuration, review install_files.sh before executing the above instructions.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to OpenCV

Post by JHPJHP »

Updated the Demo Linux Interface:
- updated the examples to include an icon
- added an icon file

Updated the Main Linux Interface with an additional 20 examples:
- cv_add_subtract.pb: add or subtract every array element of an image
- cv_addweighted_1.pb: alpha blend multiple images to simulate face morphing
- cv_addweighted_2.pb: blend a blurred copy of an image with the original
- cv_analog_clock.pb: creates an analog clock synchronized with the system time
- cv_approxpoly_1.pb: calculates the contour areas, approximating polygonal curves with specified precision
- cv_approxpoly_2.pb: calculates the contour areas, approximating polygonal curves with specified precision
- cv_bezier_curve.pb: Bézier Curve: A parametric curve frequently used in computer graphics and related fields
- cv_bounding_rectangle.pb: calculates the contour areas
- cv_calcbackproject.pb: calculating the back projection of a histogram, frequent density values are displayed as bright pixels
- cv_CAPTCHA.pb: CAPTCHA: Completely Automated Public Turing test to tell Computers and Humans Apart
- cv_emboss_1.pb: add an embossed filter to an image giving it a 3D shadow effect
- cv_fractal_1.pb: generates an iterative Mandelbrot Set, the most popular geometrical fractal
- cv_image_dots.pb: creates an image by averaging 10x10 block regions, and applying the color values to a dot matrix
- cv_mov_houghcircles.pb: finds circles in grayscale image frames using the Hough transform on a movie file
- cv_mov_runningavg_1.pb: calculates the weighted sum of the input image and the accumulator, used to detect moving objects of a certain size
- cv_mov_scene_detection.pb: detect scene changes on a movie file using similarity measurements between frames
- cv_pencil_sketch.pb: simulate a color / black & white pencil sketch from an image
- cv_sharpen.pb: add various edge filters to an image giving it different sharpened effects (sharpen / excessive / realistic)
- cv_stippling.pb: stippling is the creation of a pattern simulating varying degrees of shading by using small dots
- cv_thinning_1.pb: repeated iterations using an edge detection algorithm on a grayscale image producing increasingly thinner edges
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to OpenCV

Post by JHPJHP »

Updated the Main Linux Interface with an additional 20 examples:
- cv_edges.pb: add an edge filter to an image detecting edges in all directions
- cv_HOG.pb: Histogram of Oriented Gradients (HOG) is used to detect objects
- cv_kalman_1.pb: the Kalman filter is an algorithm which operates recursively on streams of noisy input data to produce a statistically optimal estimate of the underlying system state
- cv_kalman_2.pb: tracks a rotating point at a constant rotation speed where both state and measurement vectors are a 1D point angle
- cv_kmeans_1.pb: image segmentation by k-means clustering and color reduction
- cv_kmeans_2.pb: generates an image with random points grouped by a random number of cluster centers
- cv_laplace.pb: calculates the Laplacian of an image
- cv_LBP.pb: Local Binary Pattern: An efficient texture operator thresholding the neighborhood of each pixel
- cv_lomo.pb: simulates the LOMO (Leningrad Optical Mechanical Association) camera lens effect
- cv_motion_blur.pb: add a motion-blur filter to an image blurring in only one direction
- cv_oil_painting.pb: create an oil painting effect applied to the loaded image
- cv_radial_blur.pb: blurs an image towards a selected point
- cv_resize.pb: resizes an image to a specified percent
- cv_retro.pb: retro-style photo effect done by adding noise to the luminance channel and reducing intensity of the chroma channels
- cv_rotate_1.pb: calculates an affine matrix of 2D rotation, applying the transformation to an image
- cv_rotate_2.pb: retrieves pixel quadrangle with sub-pixel accuracy, applying 2D rotation to an image
- cv_saliency.pb: a fine-grained saliency algorithm is applied to an image: The distinct subjective perceptual quality which makes some objects stand out from their neighbors
- cv_sobel.pb: calculates the first, second, third, or mixed image derivatives using an extended Sobel operator
- cv_vignette.pb: applies the Vignette effect, the process by which there is loss in clarity towards the corners and sides of an image
- cv_watercolors.pb: apply a watercolor effect to an image using a recursive bilateral filter
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to OpenCV

Post by JHPJHP »

Updated the Main Linux Interface with an additional 10 examples:
- cv_chessboard.pb: generates the top view of a chessboard pattern from its perspective view
- cv_color_balance_1.pb: balance color by scaling the histogram of the RGB channels
- cv_color_balance_2.pb: balance color by contrast stretching the RGB channels, or applying a normalize algorithm
- cv_color_transfer.pb: performs a color transfer between two images
- cv_contours_1.pb: calculates the contour areas
- cv_contours_2.pb: calculates the contour areas
- cv_convertimage.pb: converts from one image to another with optional vertical flip
- cv_convexhull_1.pb: finds the convex hull of a point set
- cv_convexhull_2.pb: calculates the contour areas, finding the convex hull of point sets, and approximating polygonal curves with specified precision
- cv_depth_of_field.pb: using a second image as a mask to compare against an object in the original image, depth of field is simulated

NB*: Also applied a small update to the IncludeFile pb_procedures.pbi.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: PureBasic Interface to OpenCV

Post by wilbert »

JHPJHP wrote:Updated the Main Linux Interface with an additional 10 examples:
Good to see you are supporting Linux as well now.
Your speed of converting examples is really fast !!! :shock: :)
Windows (x64)
Raspberry Pi OS (Arm64)
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to OpenCV

Post by JHPJHP »

Hi wilbert,
wilbert wrote:Good to see you are supporting Linux as well now.
Without your previous patience and support during the OSX conversion, the Linux interface may not have happened. Thank you for your positive comments.

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

Updated the Main Linux Interface with an additional 50 examples:
- cv_convexitydefects.pb: calculates the contour areas, finding the convex hull of point sets to convexity defects
- cv_copymakeborder.pb: show various border styles on a loaded image
- cv_cornerharris_1.pb: calculates a feature map for corner detection using the Harris edge detector
- cv_cornerharris_2.pb: calculates a feature map for corner detection using the Harris edge detector
- cv_cvtcolor.pb: converts an image from one color space to another
- cv_DCT.pb: performs a discrete cosine transform of a 1D array, first displaying its power spectrum then incrementally reducing noise
- cv_detect_hand.pb: contour extraction and calculation is used to determine finger locations
- cv_DFT.pb: performs a discrete Fourier transform of a 1D floating-point array, displaying its power spectrum
- cv_distortion_1.pb: distort a color image by manipulating pixel locations
- cv_distortion_2.pb: distort a grayscale image by manipulating pixel locations
- cv_disttransform_1.pb: calculates the distance to the closest zero pixel for each pixel of the source image
- cv_disttransform_2.pb: calculates the distance to the closest zero pixel for each pixel in the image
- cv_doodle.pb: utilizing OpenCV's mouse callback, adds the ability to doodle on the loaded image
- cv_draw_spiral.pb: draw a circular or square spiral
- cv_drawing.pb: a demonstration of OpenCV's drawing and text output functions
- cv_emboss_2.pb: apply a raised or pressed embossed style effects to an image
- cv_emboss_3.pb: using an extended Sobel operator an embossed effect is achieved
- cv_encode_decode.pb: encode / decode a 4 channel image where the black areas have been converted to transparency
- cv_enhance_detail.pb: enhance the details of an image
- cv_enhance_edges.pb: enhance the edges of an image in 2 stages using various filters
- cv_find_license_plate.pb: license plate recognition
- cv_find_shapes.pb: approximates a polygonal curve(s) with the specified precision
- cv_find_speed_sign.pb: speed sign recognition
- cv_find_squares.pb: find squares in an image
- cv_fisheye.pb: standard fisheye lens effect derived from mathematical equations
- cv_fitellipse_1.pb: creates a sequence of points, bounding them in an ellipse of the minimal area
- cv_fitellipse_2.pb: calculates the contour areas
- cv_flip.pb: flips a 2D array around vertical, horizontal, or both axes
- cv_floodfill.pb: demonstration of the FloodFill function, filling a connected component with a given color
- cv_folding.pb: transform an image to show a folding effect at a defined cycle
- cv_mov_runningavg_2.pb: calculates the weighted sum of the input image and the accumulator, so that the new image becomes a running average of a frame sequence
- cv_parametric_curve.pb: Parametric Curve: A curve defined as a function of independent variables
- cv_pb_font.pb: draw text using PureBasic commands with any font onto an OpenCV generated image
- cv_setimageROI.pb: simulates zooming a section of a resized image by loading the Region Of Interest (ROI) for a given rectangle from the original image
- cv_siemens_star.pb: Siemens Star: A pattern used to test the resolution of optical instruments, printers and displays
- cv_smooth_edges_1.pb: smooth the edges of an image using a normalized convolution filter
- cv_smooth_edges_2.pb: smooth the edges of an image using a recursive filter
- cv_solve_maze.pb: maze game / solve a maze using a morphological transformation
- cv_spider_web_1.pb: draw a Spider Web sketch from a color image
- cv_spider_web_2.pb: draw a Spider Web sketch from a gray-scale image
- cv_warpaffine.pb: calculates an affine transform from three pairs of corresponding points
- cv_warpperspective_1.pb: calculates a perspective transform from four pairs of corresponding points
- cv_warpperspective_2.pb: calculates a perspective transform from four pairs of corresponding points
- cv_water_ripples.pb: creates the illusion of water ripples on a background image
- cv_watershed.pb: performs a marker-based image segmentation using the watershed algorithm
- le_fitellipse_1.pb: creates a sequence of points, bounding them in an ellipse of the minimal area
- le_fitellipse_2.pb: calculates the contour areas
- le_minarearect_1.pb: creates a sequence of points, bounding them in a rectangle of the minimal area
- le_minarearect_2.pb: calculates the contour areas
- le_pyrsegmentation.pb: implementing image segmentation by pyramids, a cartoon effect is achieved
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to OpenCV

Post by JHPJHP »

Updated the Main Linux Interface with an additional 30 examples:
- cv_minarea.pb: finds the minimal area of a point set wrapping it in a circle and a rectangle
- cv_minareacircle_1.pb: creates a sequence of points, bounding them in a circle of the minimal area
- cv_minareacircle_2.pb: calculates the contour areas
- cv_minarearect_1.pb: creates a sequence of points, bounding them in a rectangle of the minimal area
- cv_minarearect_2.pb: calculates the contour areas
- cv_morph_faces_build.pb: using a combination of HaarCascades and Delaunay triangulation, multiple faces are mapped
- cv_morph_faces_show.pb: morph one face into another using data derived from lists created using Delaunay triangulation
- cv_mov_writeframe.pb: draws text to a movie file and saves it as an AVI (Audio Video Interleaved); includes a blur-in / blur-out effect
- 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
- cv_precornerdetect_1.pb: calculates a feature map for corner detection
- cv_precornerdetect_2.pb: calculates a feature map for corner detection
- cv_steganography_image_1.pb: steganography is the practice of concealing a file, message, image, or video within another file, message, image, or video
- cv_steganography_image_2.pb: steganography is the practice of concealing a file, message, image, or video within another file, message, image, or video
- cv_steganography_text.pb: steganography is the practice of concealing a file, message, image, or video within another file, message, image, or video
- cv_stereobm.pb: computes disparity using the BM (Block Matching) algorithm for a rectified stereo pair of images
- cv_thinning_2.pb: repeated iterations using multiple filters on a grayscale image producing a skeleton effect
- cv_thinning_3.pb: a five stage two-dimensional filter applied to a grayscale image producing a skeleton effect
- cv_threshold_1.pb: applies a fixed-level threshold to each array element
- cv_threshold_2.pb: applies an adaptive threshold to each array element
- cv_transparent_1.pb: using the watershed algorithm, an object can be extracted and saved to a transparent PNG file
- cv_transparent_2.pb: flood fill a color area to transparency, applied when the image has been saved to a PNG file
- le_mov_bgcodebookmodel.pb: using an average difference learning method, foreground moving objects of a certain size are tracked
- le_mov_bgstatmodel_1.pb: using a background/foreground detection algorithm, foreground objects are highlighted/removed
- le_mov_bgstatmodel_2.pb: using a Gaussian mixture-based background/foreground detection algorithm, foreground objects are highlighted
- le_mov_gaussianbgmodel.pb: using a Gaussian background model, foreground moving objects of a certain size are tracked
- pb_gl_parametric_curve.pb: using OpenGL to display various parametric curves
- pb_gl_photo_cube.pb: using OpenGL and textures, multiple images are displayed onto the surfaces of a rotating cube
Last edited by JHPJHP on Wed Apr 12, 2017 4:04 am, edited 1 time in total.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to OpenCV

Post by JHPJHP »

Updated the Main Linux Interface with an additional 30 examples:
- cv_fractal_2.pb: Fractal Art: Created by calculating fractal objects represented as images
- cv_fractal_3.pb: generates a Mandelbrot Set, the most popular geometrical fractal
- cv_fractal_4.pb: generates a Julia Set, a popular geometrical fractal
- cv_gabor_filter_1.pb: Gabor Filter: A linear filter used for edge detection
- cv_gabor_filter_2.pb: Gabor Filter: A linear filter used for edge detection
- cv_gamma.pb: Gamma Correction: The relationship between a pixels numerical value and its actual luminance
- cv_gaussian_laplacian.pb: a visual representation of a Gaussian and Laplacian Pyramid
- cv_goodfeatures.pb: determines strong corners on an image, marked by circles
- cv_haar_transform.pb: implements a Haar wavelet transform, decomposing then reconstructing the image
- cv_haardetect_face.pb: tries to detect frontal-faces of different sizes using HaarCascades
- cv_histogram_1.pb: calculates a histogram for the Red, Green, and Blue channels of an image
- cv_histogram_2.pb: calculates a histogram based on brightness and contrast levels
- cv_houghcircles.pb: finds circles in a grayscale image using the Hough transform
- cv_houghlines_1.pb: finds lines in a binary image using the probabilistic Hough transform
- cv_houghlines_2.pb: finds lines in a binary image using the standard Hough transform
- cv_laplacian_blending.pb: using a Laplacian pyramid with the help of an image mask, two images are blended together
- cv_logpolar.pb: remaps an image to log-polar space
- cv_mask_black.pb: create an image mask by replacing any non-black pixels with white
- cv_mask_color.pb: create an image mask by replacing any pixel colors that fall within the selected range with black, and any other pixels with white
- cv_match_train.pb: creates a text file to later match contours against two image files containing numbers
- cv_match_write.pb: tries to match contours learned from one image file containing numbers against another
- cv_pseudo_colors.pb: augment an image with a set of predetermined colors
- cv_pyrmeanshift.pb: performing the meanshift segmentation of an image, a cartoon effect is achieved
- cv_RTSP_writeframe.pb: using RTSP (Real Time Streaming Protocol) an online video is saved to a local folder
- cv_seam_carving_1.pb: deleting vertical seams in an image by calculating the intensity of color pixels
- cv_seam_carving_2.pb: deleting vertical seams in an image by calculating the intensity of gray-scale pixels
- cv_split_merge.pb: divides a multi-channel array into several single-channel arrays, then combines them excluding 1 channel to create a new multi-channel array
- cv_standard_deviation.pb: applies Standard Deviation to an image by calculating the square root of the variance
- cv_stylize_1.pb: stylize an image by applying various filters
- cv_stylize_2.pb: stylize an image by applying various filters
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to OpenCV

Post by JHPJHP »

Updated the Main Linux Interface with an additional 9 examples:
- cv_inpaint.pb: restores the selected region in an image using the region neighborhood
- cv_overlay_1.pb: apply a perspective transform calculated from four pairs of points to an image, overlayed onto another image
- cv_overlay_2.pb: calculates the weighted sum of two arrays; this is demonstrated by overlaying two images
- cv_pb_image_1.pb: formats a PureBasic image to work with OpenCV
- cv_pb_image_2.pb: formats a PureBasic image to work with OpenCV
- le_extractSURF.pb: detects keypoints and computes SURF (Speeded-Up Robust Features) descriptors
- le_nearest_neighbor.pb: detects keypoints and computes SURF (Speeded-Up Robust Features) descriptors, finding the two nearest neighbors
- le_stitching_1.pb: stitch together 2 images in stages; based on the SIFT (Scale Invariant Feature Transform) algorithm
- le_stitching_2.pb: stitch together 2, 3, 4, and 5 images; based on the SIFT (Scale Invariant Feature Transform) algorithm

Added folder: /problems/
- cv_maxrect.pb: cvMaxRect Function (asm error)
- cv_minarea_2.pb: cvMinEnclosingTriangle Function (unknown error)

Added folder: /pending/
- includes 52 webcam examples not yet modified to work in Linux

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

Rebuilt the OpenCV libraries :: Updated the install file

INSTALL INSTRUCTIONS:

1. Extract the OpenCV folder from the ZIP package
2. Open the /binaries/setup/ folder
3. Right-Mouse-Click selecting Open Terminal
4. Type sudo ./install_files.sh to install the required files

NB*: If you are concerned about changes to your Linux configuration, review install_files.sh before executing the above instructions.
AAT
Enthusiast
Enthusiast
Posts: 256
Joined: Sun Jun 15, 2008 3:13 am
Location: Russia

Re: PureBasic Interface to OpenCV

Post by AAT »

Hi JHPJHP!
Greate work!

Could you add 32-bit OpenCV libraries to the Linux archive?
On my computer with 32-bit Linux Mint 18.1, I get the message after compiling:

/home/at/OpenCV/includes/../binaries/libopencv_calib3d.so.2.4.13: error adding symbols: The file is in the wrong format (russian message is "Файл в неправильном формате")
collect2: error: ld returned 1 exit status

P.S. I'm newbie to Linux, now there's a good reason to try it. :)
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to OpenCV

Post by JHPJHP »

Hi AAT,

It is really good to hear from you again :!:
Could you add 32-bit OpenCV libraries to the Linux archive?
I can do one better, I've created a setup document to build your own libraries.
- included in the Linux packages: /OpenCV_Linux/binaries/setup/Setup OpenCV in Linux.pdf

After you have setup OpenCV in Linux, please test the Demo Webcam example.
- once I know it works, I will complete the final 52 examples

NB*: Not only was AAT a main contributor to the original interface, but he was also a consistent support motivating me to complete the initial release.

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

First post updated; all packages updated with some minor improvements and bug fixes.
AAT
Enthusiast
Enthusiast
Posts: 256
Joined: Sun Jun 15, 2008 3:13 am
Location: Russia

Re: PureBasic Interface to OpenCV

Post by AAT »

Hi, JHPJHP!

I tested your pb_webcam.pb example from theOpenCV_Linux_Demo pack
with my UVC webcam, here is screenshot http://rgho.st/8PPBmYDBz:

Image
Locked