Emgucv library currentFrame.Copy - emgucv

now I am working with Face detecting using Emgucv library.
I am beginner for that. I have not idea about this line
result = currentFrame.Copy(f.rect).Convert<Gray, byte>().Resize(100, 100, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
Can you please tell me?

currentFrame.Copy(f.rect) is an Image that represents the image bounded by a rectangle(f.rect), which is obtained from var f which usually represents the result of the actual detection you want to implement;
Convert() Converts it to grayscale;
Resize resizes the image to 100,100 with interpolation type Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC.
You should really read more about this.

Related

Image plotted by plt.imshow() is inverted while same image by cv2_imshow() is fine, how do I know what my neural net gets?

Here is my snippet for both of them
from google.colab.patches import cv2_imshow
import cv2
pt = '/content/content/DATA/testing_data/1/126056495_AO_BIZ-0000320943-Process_IP_Cheque_page-0001.jpg' ##param
img = cv2.imread(pt)
cv2_imshow(img)
and here is the other one
import matplotlib.image as mpimg
pt = '/content/content/DATA/testing_data/1/126056495_AO_BIZ-0000320943-Process_IP_Cheque_page-0001.jpg'
image = mpimg.imread(pt)
plt.imshow(image)
Now, the image in second case is inverted
and image on my system is upright
What I am mostly afraid of is, if my ML model is consuming inverted image, that is probably messing with my accuracy. What could possibly be the reason to It and how do I fix it
(ps: I cannot share the pictures unfortunately, as they are confidential )
(Run on google colab)
All the help is appreciated
Your picture is upside-down when you use one method for reading, and upright when you use the other method?
You use two different methods to read the image file:
OpenCV cv.imread()
Mediapipe mpimg.imread()
They behave differently. OpenCV's imread() respects file metadata and rotates the image as instructed. Mediapipe's function does not.
Solution: Stick to OpenCV's imread(). Don't use Mediapipe's function.
The issue is not with matplotlib. When plt.imshow() is called, it presents the image with an origin in the top left corner, i.e. the Y-axis grows downward. That corresponds to how cv.imshow() behaves.
If your plot does have an Y-axis growing upwards, causing the image to stand upside-down, then you must have set this plot up in specific ways that aren't presented in your question.

How to fix broken alphabet in binary image

I have one picture.
There are many broken places in the image.
Please refer to the the picture.
Who knows how to repair the broken stroke using opencv 3.0?
I used dilate operation in OpenCV and I got the picture as belows:
It looks so ugly if comparing the original image.
I am late to the party but I hope this helps someone.
Since you have not provided the original image I cannot say the following solution would work 100%. Not sure how you are thresholding the image but adaptive thresholding might give you better results. Opencv (Python) code:
gauss_win_size = 5
gauss_sigma = 3
th_window_size = 15
th_offset = 2
img_blur = cv2.GaussianBlur(image,(gauss_win_size,gauss_win_size),gauss_sigma)
th = cv2.adaptiveThreshold(img_blur,255, cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY_INV,th_window_size,th_offset)
Tinker around with the parameter values to see what values work best. It's usually a good idea to blur your image and that might possibly take care of broken binary images of alphabets. Note, blurring may eventually produce slightly thicker characters in the binary image. If this still leaves with a few broken characters then you can use morphological closing:
selem_shape = cv2.MORPH_RECT
selem_size = (3, 3)
selem = cv2.getStructuringElement(selem_shape, selem_size)
th = cv2.morphologyEx(image, cv2.MORPH_CLOSE, selem)
Again, tinker around with structuring element size and shape that works best with your images.

Crop an image into a rectangle shape when the cropping points are on any shape which has 4 points - IOS/Swift

In my project, I want to set 4 cropping points manually on an image and crop that image according to set points. For example have a look on below image.
Like this, all I want is to crop the image according to that path and after cropping it should be a rectangle. This is just like image cropping in CamScanner IOS application. If anyone have any idea how to do this any help would be highly appreciated.
Here are found very nice github project that have same funtionality what you want but this is in Objective-C might be you can convert this code in to swift check the link following:
https://github.com/jberlana/JBCroppableView
It's output is:
UPDATE
I just made one Demo in Swift using JBCroppableView Objective-C class implements in Swift. Download from the following and use as per your requirement.
https://github.com/nitingohel/NGCropview
The Combination of Swift + Objective-C
OUTPUT
I think you need geometric_transformations.
If you plan to use opencv, here is a good example:
http://www.pyimagesearch.com/2014/08/25/4-point-opencv-getperspective-transform-example/

Firemonkey drawing on bitmap without interpolation

I am using the canvas draw functions drawrect and filltext to draw onto a Tbitmap but I don't want the results antialiased. Anyone know how to do that ?
Working with OSX and Delphi XE3 (but have XE4 and XE5 if needed)
Is the problem:
the bitmap you create seems to have anti-aliasing present in the data?
or have you got a good bitmap and want to disable anti-aliasing in the viewer/display?
If it is the former, have you checked that the anti-aliasing is actually present in the bitmap, and not introduced by your viewer?
In the past I've found it useful to draw a black-on-white test pattern, and display the image at 1:1 scale. Irfanview is a nice tool for viewing at 'true' scale. Then use a loupe/peak/lens to get a close-up of the actual pixels.
Black-on-white test patterns are particularly good since you should be able to see (hopefully) that the R,G and B sub-pixels are all equally illuminated when there is no anti-aliassing present. If you draw a black-on white pattern and you get solitary bright sub-pixels then you've definitely got anti-aliassing (or some other form of corruption!).
My experience has been that image viewers often do interpolation for you, and it can be tricky to see what is going on unless you look at the actual bitmap data or have a close-up look at the unscaled image...
Hi in the drawBitmap method you need to set HighSpeed parameter to "True", in the sample below:
NewBitmap.Canvas.DrawBitmap(SmallBmp, RectF(0, 0, SmallBmp.Width, SmallBmp.Height), RectF(0, 0, NewBitmap.Width, NewBitmap.Height), 1,**True**);
rgds
Ivan

Image segmentation C#

I have a picture with a black background and gray objects and I want to filter out the objects. But the light incidence makes it impossible to just look after a color. It will either filter not the whole object or it will filter as well the background.
If some can give an hint or an example in C# it would be nice.
sory because i'm using VB.NET but hope I can help you
Dim myBitmap As New Bitmap("Grapes.jpg")
Dim pixelColor As Color = myBitmap.GetPixel(X, Y)
if pixelColor = Color.Black
myBitmap.SetPixel(X, Y, Color.Blue)
If in objects have black color. I guess you have to change others way to get the object like save object's area.
Without any example image is hard to guess. But for start you should look into histogram equalization. This method enables to balance the lightning in the image.
Wikipedia has a nice example of what hist equalization is capable of.

Resources