Commit Graph

196 Commits

Author SHA1 Message Date
Kwabena W. Agyeman
7a01a9bede Final Imlib Cleanup
Finished going through imlib.c.
-> Histeq uses fb_alloc now and has hook for RGB histeq when reserve YUV
LUT is added (coming soon in next PR).

Cleanuped py_helper.c/h
-> No functional changes. Just added some header info.

Finished going through py_image.c
* 1 - Finished general code cleanup and updating everything to using new
library functions. In particular, I updated the remaining find_*
functions with the new roi clipping code when they accept rois.
* 2 - Made blob stuff return a list when nothing is found so you don't
have to do an if on the returned value anymore.
* 3 - img subscr is more powerful now allowing image reading and
writing. I updated this because I had to use it to find a previous bug
with socket.send() for the WINC driver.
* 4 - Renamed find_eyes to find_eye. Because it just finds one eye.
* 5 - Other than that just general code cleanup to make functions look
consistent.

And yes, changes have been test. Face tracking, eye tracking, keypoints,
etc. all work still.

Future things todo before release:
1 - Change all LAB stuff to YUV.
2 - Add in reverse YUV->RGB LUT and update functions like Mode() to use
this so they don't generate messed up outputs, also histeq() too.
3 - Add any remaining sensor control functions like agc control.
2016-04-25 21:55:49 -04:00
Kwabena W. Agyeman
367e5fdd3d Improved JPEG capabilities.
* Added the ability to control the quality on JPEG functions... However,
due to our JPEG implementation this doesn't seem to help. 90% JPEG
quality images and regular images should be about equal. But, you can
see heavy degredation with 90% still. E.g. text is unreabable. Not
exactly sure why this is happening but it can be fixed later.

* Changed the compress() function to compressed(). Also, it now
compresses using FB_Alloc to prevent realloc issues when compressing.

* Added new compress() function. This function compresses an image in
place and if that image is the frame bufffer then it will update the
frame buffer bpp value to reflect the image was compressed. Users can use
this function to basically finalize the frame buffer and then pass the FB
to functions that need to send image bytes. The benefit of using this
function is that it should allow higher quality JPEGs and let everything
run at a faster speed while connected to the IDE.

I made this function to speed up WiFi. However, I encountered a bug with
the winc.send() method. It appears to zero the bytes it sends. I didn't
debug further except to verify that the image data became zero after
calling send.
2016-04-23 16:37:21 -04:00
Kwabena W. Agyeman
b534dc6ffc Imlib cleanup
*Changed subimg to copy.
*Made blend work the same way as all our other double image argument
functions.
*Changed bilt to replace (the name of bilt is way to esoteric). Replace
gives you the basic assignment op.
* Removed scale/sacled. I removed this code because we don't want to
encourage people to scale things and allocate additional images in
memory. I decided to keep copy() for completeness sakes... but, I don't
see anyone using it. (By completeness sakes I mean that we now have the
assignment op, copy op, etc. for an image object).
* Removed rainbow. This feature is built into the FIR module now.

Moving on, compress needs to be renamed to compressed and a new compress
function will need to be added.

The compress() function will compress the image (or frame buffer, etc)
and not return a new object. The compressed() function will return a new
object and not compress the original image.

The compress function will make it easier for users to compress images
once they are done working on them before sending the image some where.
I don't see compressed() being used much then after adding the
compress() function. Since the compress() function won't use up heap
space this makes it very good.
2016-04-19 21:42:56 -04:00
Kwabena W. Agyeman
16daeb83a2 Fixed blob code.
Removed micropython code from the image libary. Also, blobs are now 10
tuple values by default now. The multilist thing has been removed from
blobs and it will return just a list of blobs instead of a tree of
lists.

Filter functions still work too.
2016-04-13 23:16:51 -04:00
Kwabena W. Agyeman
9e5d379c18 Remove old code.
Pixels, centroid, and orientation are calculated in the blob code now.
As for threshold, it is no longer needed (plus, it required storing a
secondary image in RAM which isn't really something we can handle).
2016-04-09 19:32:14 -04:00
Kwabena W. Agyeman
d1ff36602a New blob code.
Blob tracking has now been updated to work without requiring prior
segmentation of the image. You can still run it on a segmented image,
but, that is not needed anymore.

Use the copy color feature of the OpenMV IDE to get a color in the
image. Once you have that you can then pass the color to find_blobs which
will output a tuple of lists of blobs for each color. By default, all
blobs less than 1/1000th of the image are filtered out, however, you can
add a custom filter function which gets the image and the blob about to
be added to the list and you can decide to filter it or not.

For marker tracking, we now have a function called find markers which
basically merges all the blobs found by find blobs into one list of
blobs. Each new blob will have a color code value which will tell you
what colors are part of that blob. We support tracking up to 30 unique
colors this way.
2016-04-09 11:43:35 -04:00
Kwabena W. Agyeman
401b7b72a8 Added mean, median, and mode filters.
Mean filter -> Fast and easy to use. This will likely be the only filter
that gets alot of action on the M4.

Median filter -> Works really well, but, slow. On grayscale at 160x120
you can get also 10 FPS with it for a 3x3 kernel. That said, it's still
slow. Also, the code only works for 3x3 and 5x5 kernels.

About the previous histogram filter... technically, that filter should be
better. However, it suffers from a startup cost. The operation of finding
the median point in the histogram costs too much to compute. This is
what causes it to be slow. On very large kernels it will be faster than
the sorting median alrogithm I put up... but, large kernels will be too
slow for anyone to use anyway. The paper Ibrahim linked to about it
showed it being used for like 7x7 kernels and up... so, I think the
researcher who thought of the idea was really thinking about the
algorithm for large kernels.

Mode filter -> Works great on grayscale. Not so much on color. I think it
needs to be run on the LAB color space instead of the RGB color space. I
say this because it causes pretty strong artifacts around edges. When we
get more flash we'll be able to have a reverse lookup table for LAB to
make the mode filter better. Until then...
2016-04-04 20:04:50 -04:00
Kwabena W. Agyeman
978b4c12df Add Midpoint filter.
Has a bias value that allows you to control if its really a midpoint,
min, max filter, or something inbetween. Run at 160x120 or lower. 320x240
is slow (seems to be the case for all convoltions at that res).
2016-03-25 21:26:20 -04:00
Kwabena W. Agyeman
0ded05e333 Add color functions.
Now you can convert from rgb to lab/grayscale and vice-versa. Without
this functionality it would be hard to deal with moving between RGB and
LAB.
2016-03-03 23:48:04 -05:00
Kwabena W. Agyeman
488253a8b0 Add statistics function.
You can now get the color stats for an area in the image. The stats
function returns the mean, median, mode, min, max, st_dev,
lower_quartile, and upper_quartile.

This function allows you to automate binary and threshold functions
based on what's in the iamge.
2016-03-01 21:43:52 -05:00
Kwabena W. Agyeman
6ed08213b5 Fix unintialized error.
If the rect was not intersecting these functions would have returned bad
values.
2016-02-29 21:31:59 -05:00
Kwabena W. Agyeman
98f4dde21f Add new morph function.
The morph function lets you convolve the image with a kernel. It's
decently fast right now. But, in the future we'll have to optimize it by
a lot (unrolling loops, using SIMD instructions, etc.).

Anyway, along with morph I added an edge detection test script showing
how you can use a high pass filter on an image to get all the edges in
it. This is not as good as canny edge dection... but, it's about the
same and fast enough.

We'll need a Hough Transform system in the future to make edge dection
useful. Not sure how that will be implemented... so, that's going to be
far away for now.
2016-02-29 18:04:45 -05:00
Kwabena W. Agyeman
fb8b357c24 Dilate and errode working.
The old code did not actually implement the errode anhd dilate kernels
correctly. However, it migh have been a little faster because it avoided
the boundary problem.

In the future we can optimize all the kernel code to have different loops
for doing the edges of image versus the center. But, for now, this is
good enough. QVGA color tracking with kernels will be slow, but, the
speed can be improved with QQVGA resolution. Using a 3x3 kernel is
plenty fast. Larger ones are slower.

I also added the ability for you to set the threshold for erode and
dialte. This lets you make the kenrel a little bit smarter so that it
won't errode or dilate a pixel unless the threshold is met. Meaning,
you'll be able to use erode to erode an image down to 1 pixel wide
lines.
2016-02-28 16:27:49 -05:00
iabdalkader
7e1a4169a7 Add match_descriptor function.
* A single function to match LBP/FREAK descriptors.
2016-02-28 03:39:13 +02:00
iabdalkader
154cb5be69 Change descriptor functions to accept file pointer. 2016-02-28 03:22:07 +02:00
iabdalkader
acafef5207 Revert HaarCascade.
* HaarCascade doesn't really fit into generic descriptor functions.
2016-02-28 02:37:35 +02:00
iabdalkader
67acf7188c Use one load/save function for all descriptors. 2016-02-28 01:38:24 +02:00
Kwabena W. Agyeman
4ed49082a1 Background Subtraction is working!!!
Woot, all the effort to make it so you can manipulate the image buffer
with an image off disk works!

Try out the motion_detection script.
2016-02-27 11:58:37 -05:00
Kwabena W. Agyeman
1121a6f7df Fixed save image.
It now figures out the file type from the file extension. If no file
extension is given it just saves the file as BMP if its not a JPEG image
or JPEG if it's a JPEG image. If you specify an extension and the file is
not of that type then it will give you an error.

The new test_save.py should run until you reach the JPEG image part
where it quits due to lack of JPEG support natively on OV7725 boards.
Maybe JPEG mode should be supoorted by just compressing pictures?
2016-02-26 22:00:04 -05:00
iabdalkader
2b27d1542f Add save LBP descriptor. 2016-02-26 23:12:15 +02:00
Kwabena W. Agyeman
ac3d1e4373 Add BMP/PNM/JPEG image file loading and saving.
There's not a lot of actual functionality changes from the last commit.
However, switching the basic wrapper library to just long_jump on
failure and moving all the state info to structs required changes to all
the base functions in the last commit. The rest of the changes are to
link in the new functionality and to get the code to compile (usbdbg.c
edits).

Next I'll work on a function which abstracts the problem of opening an
image up and executing a line by line function op on it. I already
worked the code out for that. But, it's not in this commit to keep
things streamlined.
2016-02-25 22:26:56 -05:00
iabdalkader
074cf9d5e4 Add pointer to matching keypoint to kp_t struct.
* This way we don't need to allocate the array of matching keypoints
and risk running out of memory due to fragmentation. So all or nothing.
2016-02-26 01:44:23 +02:00
iabdalkader
5ff5419bf1 Return empty list if no blobs were found.
* Fixes #81
2016-02-26 00:47:31 +02:00
Kwabena W. Agyeman
d8ac8f9408 Fix swap bug.
The code clearly did not swap mins and maxes.
2016-02-24 19:07:57 -05:00
iabdalkader
4d7db778fb Remove angle from keypoint.
* Not really used right now and saves 4 bytes per keypoint.
2016-02-23 20:43:33 +02:00
iabdalkader
3a747ef952 Use arrays in FAST/FREAK keypoints.
* Using arrays for FAST/FREAK keypoints, this saves some memory
allocated for intermediate data.
2016-02-23 18:19:49 +02:00
iabdalkader
7a22cb3e5c Extract keypoints in one step.
* Make find_keypoints extract FAST keypoints.
2016-02-23 00:55:54 +02:00
iabdalkader
93d3885a3c Set keypoints threshold range between 0 and 100. 2016-02-22 20:31:24 +02:00
iabdalkader
9d02e2a42a Make match_lbp accept roi and extract second LBP. 2016-02-22 19:41:16 +02:00
iabdalkader
473b8025bf Fix assertion in find_features. 2016-02-22 19:39:26 +02:00
iabdalkader
015181588a Fix assertion in find_features. 2016-02-22 19:35:11 +02:00
iabdalkader
ddcb170af0 Cleanup py_image.c
* Code cleanups in py_image.c
2016-02-22 19:17:14 +02:00
iabdalkader
124a31772c Rename helper functions. 2016-02-22 18:47:35 +02:00
iabdalkader
5860695f5d Move helper functions to new files. 2016-02-22 18:41:50 +02:00
iabdalkader
0f48c12a89 Replace all mp_map_lookup()s with helper functions. 2016-02-22 18:35:00 +02:00
iabdalkader
93dc73c7f2 Fix arg to get_rectangle_kw. 2016-02-22 18:00:20 +02:00
iabdalkader
4c63721efa Use default roi when calling save_image 2016-02-22 17:55:26 +02:00
iabdalkader
4e5b200bdf Make keypoints_match return the % of matching kpts.
* Change keypoints_match to return the percentage of matching keypoints.
2016-02-22 03:31:15 +02:00
iabdalkader
032a6e3e4d Make Haar detector work on ROIs. 2016-02-21 23:01:34 +02:00
iabdalkader
50e53c91bc Change Iris detector to work on a single region.
* This allows the detector to work on ROIs detected by the eye Haar
  cascade, which improves the accuracy and speed of the detection.
2016-02-21 20:38:01 +02:00
Kwabena W. Agyeman
c3cfb117d0 Add frame differencing functions.
The negate function gives you the ability to negate an image before
running difference on it. The difference function will subtract two images
from each other and return the abs() of the result.

I believe it would have been optimal to work on the RGB565 image in the
LAB color space. However, since we don't have an inverse LAB lut this is
not possible. If we could replace LAB with YUV then that would free up
space to have an inverse YUV table (YUV->RGB).
2016-02-20 20:29:19 -05:00
Kwabena W. Agyeman
88d9c02a1b Draw keypoints now accepts lists.
Made draw keypoints accept lists of (x, y, angle) tuples. I did this so
it could be used to show object rotation easily.
2016-02-20 16:04:59 -05:00
Kwabena W. Agyeman
0606f5be44 Added binary image functions.
Pixels, centroid, orientation, along with the basic binary tool kit
functions like and/or/xor.
2016-02-20 11:46:26 -05:00
Kwabena W. Agyeman
b01adfee26 Fixed up drawing code and scripts along with drawing code.
Set pixel works too now.
2016-02-19 22:55:50 -05:00
Kwabena W. Agyeman
a035aae493 Fixed set pixel. 2016-02-19 21:05:02 -05:00
iabdalkader
8d47b7b9b2 Add helper functions to lookup color and int. 2016-02-20 01:24:29 +02:00
Kwabena W. Agyeman
bcd5151412 New drawing functions.
All the drawing functions have been updated to handle automatic clipping
when drawing offscren and work with both grayscale and RGB565.
Additionally, all functions now accept color arguments.

I've also updated the example scripts with the new functions and tested
them out to make sure they work.

Additionally, I wrote a test suite for the drawing functions to make
sure they work.
2016-02-18 22:40:12 -05:00
Kwabena W. Agyeman
f9ae24f3a0 Reverted commands back to old argument format. 2016-02-17 23:50:08 -05:00
Kwabena W. Agyeman
dd6a322646 Added basic image querying functions.
Now you can get the width/height/format along with size. Additionally, I
fixed up get and set pixel.
2016-02-17 23:04:23 -05:00
iabdalkader
31679cab9a Allow Haar detector to accept ROIs. 2016-02-17 22:36:57 +02:00
iabdalkader
d3d7e5dc39 Use typdef's for sensor enum and structs. 2016-02-17 19:46:45 +02:00
Ibrahim Abd Elkader
020ed9369a Merge pull request #63 from kwagyeman/master
Fixed up array functions.
2016-02-15 02:45:11 +02:00
Kwabena W. Agyeman
84a964f930 Fixed up array functions.
There were a lot of missing features in the array module. I added
quicksort based on the MP sort function and I expanded the array code so
you can do stuff like take() which lets you get an object from an array
and easily put it into another array.

I also fixed the "struct array" problems in the code. Anonymous structs
have to go.
2016-02-14 19:29:34 -05:00
iabdalkader
46d91cc95a VJ: Use a scanning step proportional to scale. 2016-02-15 00:58:17 +02:00
iabdalkader
74d084ee6b Add frame size check to keypoints 2016-02-09 01:05:34 +02:00
iabdalkader
69cd07e923 Add sanity checks and meaningful error messages. 2016-02-07 02:34:47 +02:00
iabdalkader
8fabc9b35a Fix image module globals_dict_table 2015-09-22 02:27:51 +02:00
iabdalkader
d031ea87f1 Implement set_pixel 2015-08-20 16:25:37 +02:00
iabdalkader
eb29fc8894 Add sanity checks to draw_string 2015-08-13 23:15:35 +02:00
iabdalkader
54288c5351 Add image module
* Move Image class and misc functions to image module
2015-08-09 13:00:06 +02:00
iabdalkader
856938fea5 Add image get/set pixel 2015-07-31 14:13:09 +02:00
iabdalkader
269345303b Add image subscr 2015-07-31 12:37:45 +02:00
iabdalkader
f34b07f015 Update print function 2015-07-18 07:05:13 +02:00
iabdalkader
765632af91 Check number of stages when loading cascade 2015-07-10 04:10:03 +02:00
iabdalkader
e273e43961 Add stages kw arg to load cascade function 2015-07-10 02:57:30 +02:00
iabdalkader
e00d92f6f7 Fix find_features
* Add all objects to returned list.
2015-07-10 01:36:26 +02:00
iabdalkader
9b068dd992 Add extern ffs_strerror 2015-04-25 23:06:36 +03:00
iabdalkader
ef9bf26981 Add Eye Detector 2014-10-25 15:33:02 +02:00
iabdalkader
cf92de7c8a Modify LBP to use a cascade 2014-10-21 16:51:07 +02:00
iabdalkader
a2780e5a5a Add invert,binary 2014-10-21 16:47:00 +02:00
iabdalkader
90309715c9 Pass RGB to image_threshold and convert to LAB 2014-09-28 16:40:06 +02:00
iabdalkader
ce3d435137 Add load_lbp 2014-09-24 22:25:14 +02:00
iabdalkader
65cd8a133a Update license
* Switch to MIT
* Add license notice to source files
2014-09-20 05:09:52 +02:00
iabdalkader
5f51438029 Add LBP 2014-09-20 02:02:22 +02:00
iabdalkader
8854f0a9d5 Add JPEG encoder 2014-09-17 21:39:19 +02:00
iabdalkader
dcd65daee5 Add threshold, scale KW args to VJ detector 2014-09-12 20:53:43 +02:00
iabdalkader
8bfc2c92a9 Add threshold param to haar detector 2014-09-12 14:32:18 +02:00
iabdalkader
918026a22c Use ROI in Keypoint detector 2014-09-12 13:56:08 +02:00
iabdalkader
f8e08b9749 Add draw_line 2014-09-11 07:05:36 +02:00
iabdalkader
b8d989be57 Update MP branch 2014-09-10 23:16:37 +02:00
iabdalkader
c70960d17e Add save descriptor from ROI 2014-09-10 18:59:34 +02:00
iabdalkader
903f756a7c Misc Fixes, add load/save descriptor 2014-09-09 15:07:22 +02:00
iabdalkader
734eca7e97 Add Color to draw_string 2014-09-03 19:16:41 +02:00
iabdalkader
2e81c7a150 Cleanup Haar code 2014-09-03 16:14:17 +02:00
iabdalkader
b2eb44910a Add subimg 2014-09-02 16:29:20 +02:00
iabdalkader
5fdd6e09a3 Add font rendering 2014-09-01 23:43:06 +02:00
iabdalkader
29202f1f99 Add morphological operations, fix threshold 2014-09-01 16:50:58 +02:00
iabdalkader
25abc200f9 Add FAST/FREAK detector
* Remove SURF code and MP functions
* Add FAST/FREAK keypoint extractor/descriptor
* Add FAST/FREAK Python example
2014-08-27 17:34:58 +02:00
iabdalkader
9572faf78f Add scaled function
* Returns new scaled image
2014-08-25 14:32:31 +02:00
iabdalkader
f1861a332a Add scale, blit and blend functions
* Add scale, blit, blend and rainbow
* Update imlib header
* Export new functions to MP
2014-08-18 12:36:47 +02:00
iabdalkader
30169f3aaa Add buffer protocol to image 2014-06-30 03:46:32 +02:00
iabdalkader
f23336e3ae Return the number of SURF matches 2014-06-25 19:50:45 +02:00
iabdalkader
ad65c304dd Fix exceptions 2014-06-19 23:21:04 +02:00
iabdalkader
c1dab26fca Fix more sources to use HAL 2014-06-18 21:20:22 +02:00
iabdalkader
1e4b6fa8fd Update sources to new HAL 2014-06-18 17:28:46 +02:00
iabdalkader
4df970b418 Move files to OMV 2014-06-14 12:28:45 +02:00