PureBasic Interface to OpenCV

Developed or developing a new product in PureBasic? Tell the world about it.
AAT
Enthusiast
Enthusiast
Posts: 259
Joined: Sun Jun 15, 2008 3:13 am
Location: Russia

Re: PureBasic Interface to OpenCV ---- 03/06/14 08:15 PM

Post by AAT »

Ok, i'll delete my post.
---------------------
It's all right for now.
Good night! :)
User avatar
JHPJHP
Addict
Addict
Posts: 2251
Joined: Sat Oct 09, 2010 3:47 am

Re: PureBasic Interface to OpenCV ---- 03/12/14 07:00 PM

Post by JHPJHP »

Updated:
- added Constants, Macros, Structures, Functions, Inline Functions (converted to Procedures), Procedures
- renamed 3 examples
-- cv_kalman.pb to cv_kalman_1.pb
-- cv_chessboard.pb to cv_cam_chessboard.pb
-- cv_face.pb to cv_faces.pb
- added 6 examples
-- cv_kalman_2.pb: Kalman filter demonstrated by tracking the mouse
-- cv_chessboard.pb: generates the top view of a chessboard pattern from its perspective view
-- cv_cam_camshift.pb: using the Camshift algorithm, color information is used to track on object along an image sequence
-- cv_cam_select_1a.pb: utilizing OpenCV's mouse callback, adds the ability to select an area on the webcam interface
-- cv_cam_select_1b.pb: utilizing OpenCV's mouse callback, adds the ability to select an area on the webcam interface
-- cv_cam_effects.pb: pixel manipulation through direct memory access, demonstrating webcam effects
- updated / renamed / split 1 example
-- cv_border.pb
--- cv_borders.pb: shows OpenCV's available border styles on a loaded image
--- cv_doodle.pb: utilizing OpenCV's mouse callback, adds the ability to doodle on the loaded image
- updated 2 examples
-- cv_kalman_1.pb: tracks a rotating point at a constant rotation speed
-- cv_cam_chessboard.pb: finds the positions of internal corners for an 8 x 8 chessboard pattern
- added 1 default image

Includes:
- over 200 new Functions (supporting Structures, Constants, etc.)
-- added all the remaining functions from the included DLLs, except the legacy DLL

Note:
- cv_kalman_2.pb: original source found here
- cv_chessboard.pb: original source found here
- cv_cam_camshift.pb: original source found in a previous version of OpenCV

NB*: Update also includes various bug fixes and improvements to the overall stability of the package.

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 ---- 03/14/14 04:20 AM

Post by JHPJHP »

Updated:
- deleted 1 example
-- cv_rotate_1a.pb
- renamed 2 examples
-- cv_rotate_1b.pb to cv_rotate.pb
-- cv_warp_2.pb to cv_warp_2a.pb
- combined 2 examples
-- cv_erode.pb and cv_dilate.pb to cv_erode_dilate.pb
- added 1 example
-- cv_warp_2b.pb: calculates a perspective transform from four pairs of the corresponding points
- updated 3 examples
-- cv_morphology.pb: performs advanced morphological transformations using a specific structuring element
-- cv_warp_1.pb: calculates an affine transform from three pairs of the corresponding points
-- cv_warp_2a.pb: calculates a perspective transform from four pairs of the corresponding points
- added 2 default images

cv_warp_2b.pb: original source found here.
- this example reverses the warped image effect

Updates to cv_erode_dilate.pb and cv_morphology.pb are based on included examples found in the current version of OpenCV.

NB*: Update also includes various bug fixes.

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 ---- 03/14/14 06:10 PM

Post by JHPJHP »

Updated:
- merged / updated 6 examples
-- cv_gray.pb and cv_swap_2.pb to cv_cvtcolor.pb
-- cv_pyrup.pb and cv_pyrdown.pb to cv_pyrup_pyrdown.pb
-- cv_threshold_1a.pb and cv_threshold_1b.pb to cv_threshold_1.pb
- renamed 3 example
-- cv_swap_1.pb to cv_convertimage.pb
-- cv_swap_3.pb to cv_split_merge.pb
-- cv_cam_split_colors.pb to cv_cam_split_merge.pb
- updated 3 examples
-- cv_cvtcolor.pb: converts an image from one color space to another
-- cv_convertimage.pb: converts from one image to another with optional vertical flip
-- cv_kalman_2.pb: Kalman filter demonstrated by tracking the mouse
- added the OpenCV file: highgui.mht

NB*: General updates to improve the existing examples, and remove redundancy.

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 ---- 03/15/14 04:30 AM

Post by JHPJHP »

Updated:
- renamed 45 examples
-- cv_cam_motion.pb to cv_cam_motionhistory.pb
-- cv_borders.pb to cv_copymakeborder.pb
-- cv_mov_text.pb to cv_mov_writeframe.pb
-- cv_compare.pb to cv_norm.pb
-- cv_plate.pb to cv_find_plate.pb
-- cv_distance.pb to cv_disttransform.pb
-- cv_harris.pb to cv_cornerharris.pb
-- cv_corner.pb to cv_precornerdetect.pb
-- cv_faces.pb to cv_haardetect_face.pb
-- cv_cam_face.pb to cv_cam_haardetect_face.pb
-- cv_squares.pb to cv_find_squares.pb
-- cv_cam_flow_1a.pb to cv_cam_flowpyrlk_1a.pb
-- cv_cam_flow_1b.pb to cv_cam_flowpyrlk_1b.pb
-- cv_cam_flow_2.pb to cv_cam_flowfarneback.pb
-- cv_cam_good.pb to cv_cam_goodfeatures.pb
-- cv_cam_capture_1.pb to cv_cam_saveimage.pb
-- cv_cam_capture_2a.pb to cv_cam_writeframe_1.pb
-- cv_cam_capture_2b.pb to cv_cam_writeframe_2.pb
-- cv_hough_1a.pb to cv_houghlines_1a.pb
-- cv_hough_1b.pb to cv_houghlines_1b.pb
-- cv_hough_2.pb to cv_houghcircles.pb
-- cv_mov_hough.pb to cv_mov_houghcircles.pb
-- cv_warp_1 to cv_warpaffine.pb
-- cv_warp_2a.pb to cv_warpperspective_1a.pb
-- cv_warp_2b.pb to cv_warpperspective_1b.pb
-- cv_cam_warp.pb to cv_cam_warpperspective.pb
-- cv_approxpoly.pb to cv_find_shapes.pb
-- cv_contours_1.pb to cv_contours.pb
-- cv_contours_2a.pb to cv_boundingrectangle.pb
-- cv_contours_2b.pb to cv_boundingcircle_1.pb
-- cv_contours_3.pb to cv_convexhull_1.pb
-- cv_contours_4a.pb to cv_approxpoly_1a.pb
-- cv_contours_4b.pb to cv_approxpoly_1b.pb
-- cv_contours_5.pb to cv_convexhull_2.pb
-- cv_contours_6a.pb to cv_minarearect_1.pb
-- cv_contours_6b.pb to cv_fitellipse_1.pb
-- cv_contours_7.pb to cv_convexitydefects.pb
-- cv_sequence_1.pb to cv_boundingcircle_2.pb
-- cv_sequence_2a.pb to cv_minarearect_2.pb
-- cv_sequence_2b.pb to cv_fitellipse_2.pb
-- le_contours_6a.pb to le_minarearect_1.pb
-- le_contours_6b.pb to le_fitellipse_1.pb
-- le_sequence_2a.pb to le_minarearect_2.pb
-- le_sequence_2b.pb to le_fitellipse_2.pb
-- le_delaunay.pb to le_delaunay_voronoi.pb
- updated 1 example
-- cv_convexitydefects.pb: calculates the contour areas, finding the convex hull of point sets to convexity defects
- replaced 1 image

NB*: The big (update) push these last couple days is to get the package to a final state.

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 ---- 03/15/14 10:30 PM

Post by JHPJHP »

Updated:
- combined 4 examples
-- cv_disttransform.pb and cv_normalize.pb to cv_disttransform.pb
-- cv_equalize.pb and cv_cam_split_merge.pb to cv_cam_split_merge.pb
- updated 14 examples
-- cv_canny.pb: finds edges in an image using the [Canny86] algorithm
-- cv_cornerharris.pb: harris edge detector
-- cv_cvtcolor.pb: converts an image from one color space to another
-- cv_filter2d.pb: convolves an image with the kernel
-- cv_kmeans_1b.pb: image segmentation by k-means clustering and color reduction
-- cv_laplace.pb: calculates the Laplacian of an image
-- cv_norm.pb: using a default image, the absolute difference is calculated against a directory of images, returning the closest match
-- cv_overlay.pb: calculates the weighted sum of two arrays
-- cv_pow.pb: raises every array element to a power
-- cv_precornerdetect.pb: calculates a feature map for corner detection
-- cv_sobel.pb: calculates the first, second, third, or mixed image derivatives using an extended Sobel operator
-- cv_split_merge.pb: divides a multi-channel array into several single-channel arrays
-- 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

I think I'm finally content with the package. I hope to see some PureBasic / OpenCV projects in the future; it will make it all worthwhile.

Thank you to those who have commented and / or contributed... with a special thank you to AAT for his continuous support and contributions.

NB*: Updates, new contributions, etc. will be held for at least a week before being posted.

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 ---- 03/15/14 10:30 PM

Post by AAT »

Hi, JHPJHP!

Wow! I was in business trip of only 10 days and there are so many changes here! :D
I'm glad that my dream about OpenCV library in PureBasic is realised!

Thank you for your hard and great work! I will be glad to meet you here.

Good luck!

P.S. It was my 57th downloaded package...
It was great!
User avatar
JHPJHP
Addict
Addict
Posts: 2251
Joined: Sat Oct 09, 2010 3:47 am

Re: PureBasic Interface to OpenCV ---- 03/15/14 10:30 PM

Post by JHPJHP »

Hi AAT,
The main core of the openCV is adapted to purebasiс. Thank you!
I understand that you are tired, but is it possible that project will continue a little later?
It was this quote, along with the positive responses that motivated me to push the last little bit.

I've already discovered some bugs and needed changes, but like l mentioned in my previous post, I'll wait at least a week between updates before posting a new package.
It was my 57th downloaded package...
Wow that many; makes me think I should have started an upload policy awhile ago. :)
I will be glad to meet you here.
Me too, your support and contributions have been a big asset - cheers!


It sure has been fun, at times frustrating, but all-in-all a great learning experience...

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 ---- 03/22/14 02:40 AM

Post by JHPJHP »

Updated:
- added Macros, 1 Inline Function (converted to a Procedure), 1 Procedure
- updated Functions
- deleted 1 example
-- cv_pyrup_pyrdown.pb
- renamed 8 examples
-- cv_boundingcircle_1.pb to cv_minareacircle_1.pb
-- cv_boundingcircle_2.pb to cv_minareacircle_2.pb
-- cv_canny.pb to cv_canny_1a.pb
-- cv_contours.pb to cv_contours_1a.pb
-- cv_cornerharris.pb to cv_cornerharris_1a.pb
-- cv_disttransform.pb to cv_disttransform_1a.pb
-- cv_histogram.pb to cv_histogram_1a.pb
-- cv_precornerdetect.pb to cv_precornerdetect_1a.pb
- added 9 examples
-- cv_canny_1b.pb: finds edges in an image using the Canny86 algorithm
-- cv_contours_1b.pb: calculates the contour areas
-- cv_convexhull_3.pb: finds the convex hull of a point set
-- cv_cornerharris_1b.pb: calculates a feature map for corner detection using the Harris edge detector
-- cv_disttransform_1b.pb: calculates the distance to the closest zero pixel for each pixel of the source image
-- cv_histogram_1b.pb: calculates a histogram based on brightness and contrast levels
-- cv_minarea.pb: finds the minimal area of a point set
-- cv_precornerdetect_1b.pb: calculates a feature map for corner detection
-- cv_watershed.pb: performs a marker-based image segmentation using the watershed algorithm
- updated 4 examples
-- cv_contours_1a.pb: calculates the contour areas
-- cv_convexitydefects.pb: calculates the contour areas, finding the convex hull of point sets to convexity defects
-- cv_kalman_2.pb: Kalman filter demonstrated by tracking the mouse
-- cv_resize.pb: resizes an image to a specified percent
- renamed 1 image
- added 2 images

Also includes various bug fixes and small changes - not worth documenting.

One of the more interesting new examples is cv_watershed.pb:
Image

NB*: Upload includes the last of the examples from a previous version of OpenCV that I felt complemented the package as a whole.
- cv_cornerharris_1b.pb and cv_precornerdetect_1b.pb were the exception; based on script from various online documentation

Cheers!
Last edited by JHPJHP on Wed Apr 09, 2014 4:27 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.
AAT
Enthusiast
Enthusiast
Posts: 259
Joined: Sun Jun 15, 2008 3:13 am
Location: Russia

Re: PureBasic Interface to OpenCV ---- 03/22/14 02:40 AM

Post by AAT »

Hi, JHPJHP

There is no limit to perfection: Your examples become better also more spectacular. Thanks! :D

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

For now i'm trying to set connection to an IP camera and to get video from it.
What do you think about how to check that OpenCV libraries (VC10, VC11) are built with ffmpeg support?

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

Re: PureBasic Interface to OpenCV ---- 03/22/14 02:40 AM

Post by JHPJHP »

Thanks for the acknowledgement AAT...
For now i'm trying to set connection to an IP camera and to get video from it.
What do you think about how to check that OpenCV libraries (VC10, VC11) are built with ffmpeg support?
Not sure I understood you correctly, but maybe the following will help?

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

Updated:
- added Constants, Prototype Functions
- added 1 example
-- cv_writeframe_FFMPEG.pb: saves an online video to a local folder using FFMPEG
- renamed 1 image
- added 1 image

I prototyped all the functions from opencv_ffmpeg248.dll, and included a very basic example.
- for the few tests I preformed: cvGetCaptureProperty_FFMPEG does not return information for all its properties
- I don't think you need FFMPEG to access an IP webcam, if that's what your after

Also - there were numerous, but basic changes to some of the examples - not worth documenting.

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 ---- 03/24/14 02:10 AM

Post by AAT »

Hi JHPJHP.
Many thanks for your, as always, invaluable help!

My problem with an IP camera was: there is a C code which works fine in CodeBlocks and completely similar code doesn't work in PureBasic.

C code:

Code: Select all

#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <stdio.h>

int main()
{
    CvCapture *capture = cvCreateFileCapture("rtsp://user:password@192.168.1.123:554/mpeg4");
//    CvCapture *capture = cvCreateFileCapture("http://www.fileformat.info/format/mpeg/sample/567fd6a0e0da4a8e81bdeb870de3b19c/DELTA.MPG");
    if (capture  == NULL)
    {
        printf("capture  is null, aborting...");
        return -1;
    }
    cvNamedWindow("IPcam",CV_WINDOW_AUTOSIZE);
    while (cvWaitKey(1) != 27)
    {
        IplImage *img = cvQueryFrame(capture );
        if (img == NULL)
        {
            printf("img == null ");
            fflush(stdout);
            break;
        }
        cvShowImage("IPcam", img);
    }
    cvReleaseCapture(&capture );
    return 0;
}
PureBasic code:

Code: Select all

IncludeFile "includes/cv_functions.pbi"

#CV_WINDOW_NAME = "IPcam"

Repeat
  nCreate + 1
;  *capture = cvCreateFileCapture("http://www.fileformat.info/format/mpeg/sample/567fd6a0e0da4a8e81bdeb870de3b19c/DELTA.MPG")
  *capture = cvCreateFileCapture("rtsp://user:password@192.168.1.123:554/mpeg4")
  Delay(500) 
Until nCreate = 5 Or *capture

While *capture = 0;
  Delay(500) 
;  *capture = cvCreateFileCapture("http://www.fileformat.info/format/mpeg/sample/567fd6a0e0da4a8e81bdeb870de3b19c/DELTA.MPG")
  *capture = cvCreateFileCapture("rtsp://user:password@192.168.1.123:554/mpeg4")
  Debug *capture   
Wend  

cvNamedWindow(#CV_WINDOW_NAME, #CV_WINDOW_AUTOSIZE)
*image.IplImage

Repeat
  *image = cvQueryFrame(*capture)
  If *image
    cvShowImage(#CV_WINDOW_NAME, *image)    
  EndIf
  keyPressed = cvWaitKey(10)
Until keyPressed = 27 Or ExitCV

cvDestroyWindow(#CV_WINDOW_NAME)
Your last update of the openCV package didn't help me.

But! my tired brain was visited by idea to try the program on other computer with windws7 (I work in windows xp usually )
There was an good idea: my PB program works fine in Windows 7! :)

I have no idea why it don't work in Windows XP. :(
Perhaps there are some compatibility problems of the opencv libraries (VC11 version) with Windows XP.

P.S. FFMPEG library is not very good, it is slow, so the HD image (1280*720) contains artefacts often.

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

Re: PureBasic Interface to OpenCV ---- 03/24/14 02:10 AM

Post by JHPJHP »

Hi AAT,
But! my tired brain was visited by idea to try the program on other computer with windws7
My best ideas usually happen just before REM sleep. :)
Perhaps there are some compatibility problems of the opencv libraries (VC11 version) with Windows XP.
Have you tried the VC12 binaries included with the package; should work for both Windows XP and Windows 7.
FFMPEG library is not very good, it is slow, so the HD image (1280*720) contains artefacts often.
How did you test this, my example only displays values from: cvGetCaptureProperty_FFMPEG...

... In order to view the video from the example: cv_writeframe_FFMPEG.pb, a conversion script is need to scale the frames from Avframe to Iplimage. If your speaking about the saved file, you can try changing: cvCreateVideoWriter_FFMPEG - CV_FOURCC("M", "P", "E", "G") to a different codec; may need to set the file extension to AVI.

Cheers!

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 ---- 03/24/14 02:10 AM

Post by AAT »

Hi, JHPJHP
Have you tried the VC12 binaries included with the package; should work for both Windows XP and Windows 7.
Yes, i have tried. Result is the same: my program don't work in Windows XP.
I think i have to use VC9 version of openCV, but this version is absent in OpenCV binaries for now.
How did you test this...
There are two video streams from IP cam:
Image
I have no artefacts in the "Sub stream" (low resolution, low bitrate) and i have artefacts in the "Main stream" (high resolution, high bitrate) often.
The more fast processor is in the computer, the less artefacts are in the video.

But there are no artefacts in the program came with the camera at all.

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

I've tested one more IP cam with rtsp and http protocols. I think i will write small instruction soon.


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

Re: PureBasic Interface to OpenCV ---- 03/26/14 10:45 PM

Post by JHPJHP »

Hi AAT,

I think we're talking about two different things, but you obviously know what you're doing; let me know how it works out.

And since I'm already here I might as well post the latest bit of changes - that - and I'm excited about the new example...

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

Updated:
- renamed 5 example
-- cv_cam_PIP.pb to cv_cam_setimageROI.pb
-- cv_ROI.pb to cv_setimageROI.pb
-- le_cam_SURF.pb to le_cam_extractSURF.pb
-- le_SURF.pb to le_extractSURF.pb
-- le_SURF_NN.pb to le_nearestneighbor.pb
- updated 1 example
-- cv_convexitydefects.pb: calculates the contour areas, finding the convex hull of point sets to convexity defects
- added 1 example
-- le_stitching.pb: stitches two images together in stages; based on the SIFT (Scale Invariant Feature Transform) algorithm
- added 9 images

Also - there were basic changes to some of the examples - not worth documenting.

le_stitching.pb: original source found here.

*** Update ***
- there are now 4 sets of images incorporated into the example, including minor improvements to the code
- switched the final image output from gray scale to color

I've been playing around with the new Stitching example, and ended up with an additional example. If there is interest in this topic I will include it, otherwise it will remain excluded from the package. The example directly stitches together predefined images (2, 3, 4, and 5 exclusively) and includes an additional 14 images.

Image

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

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