grabcut | simple app | Computer Vision library

 by   CauldronDevelopmentLLC Python Version: Current License: GPL-3.0

kandi X-RAY | grabcut Summary

kandi X-RAY | grabcut Summary

grabcut is a Python library typically used in Artificial Intelligence, Computer Vision, OpenCV applications. grabcut has no bugs, it has no vulnerabilities, it has a Strong Copyleft License and it has low support. However grabcut build file is not available. You can download it from GitHub.

A simple program for interactively removing the background from an image using the grab cut algorithm and OpenCV. This code was derived from the Grab Cut example from the OpenCV project but is hopefully more usable for day-to-day tasks. See the OpenCV GrabCut Tutorial for more information.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              grabcut has a low active ecosystem.
              It has 14 star(s) with 3 fork(s). There are 3 watchers for this library.
              OutlinedDot
              It had no major release in the last 6 months.
              There are 4 open issues and 1 have been closed. There are no pull requests.
              It has a neutral sentiment in the developer community.
              The latest version of grabcut is current.

            kandi-Quality Quality

              grabcut has no bugs reported.

            kandi-Security Security

              grabcut has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.

            kandi-License License

              grabcut is licensed under the GPL-3.0 License. This license is Strong Copyleft.
              Strong Copyleft licenses enforce sharing, and you can use them when creating open source projects.

            kandi-Reuse Reuse

              grabcut releases are not available. You will need to build from source code and install.
              grabcut has no build file. You will be need to create the build yourself to build the component from source.
              Installation instructions are not available. Examples and code snippets are available.

            Top functions reviewed by kandi - BETA

            kandi has reviewed grabcut and discovered the below as its top functions. This is intended to give you an instant insight into grabcut implemented functionality, and help decide if they suit your requirements.
            • Main function
            • Reset the widget
            • Load image
            • Saves the image
            • Crop the image to alpha
            • Mouse event handler
            • Grab the cut region
            Get all kandi verified functions for this library.

            grabcut Key Features

            No Key Features are available at this moment for grabcut.

            grabcut Examples and Code Snippets

            No Code Snippets are available at this moment for grabcut.

            Community Discussions

            QUESTION

            Image Segmentation and Masking
            Asked 2021-Apr-27 at 15:29

            Need assistance with the simple task. I’m playing around with the LISC dataset that contains hematological images taken from peripheral blood and segmentation masks of manual ground truth for these graphical samples. The task is the following:

            1. Segment isolated leukocytes by removing/cropping irrelevant background elements using the segmentation masks given in the dataset. Try this on one sample only.
            2. Once accomplished, go through the whole folder, and segment/crop the rest of the samples.

            Results should be like this (these were obtained via a combination of Mask R-CNN, GrabCut, and OpenCV — but not suitable for the current project I’m working on):

            Here is the code that I’ve got so far (from jupyter notebook):

            ...

            ANSWER

            Answered 2021-Apr-27 at 15:29

            The change in colors is the result of the specified heatmap (viridis instead of binary) as noted above in comments.

            The output image has different coloration than the input image because OpenCV uses BGR rather than RGB for colors, so it's likely your red and blue channels are swapped. If you read an image with OpenCV and plot with Matplotlib or vice versa. There are two easy solutions:

            1.) Both read and plot images with OpenCV. You can replace plt.imshow(im_orig) with:

            Source https://stackoverflow.com/questions/67271730

            QUESTION

            Add alpha channel to RGB image
            Asked 2021-Jan-21 at 14:24

            How can I add alpha channel to png image? Precisely I have the background using grabcut function, now I want to add it to the png image.

            After that I want to set the alpha channel to transparent by use of a mask

            ...

            ANSWER

            Answered 2021-Jan-21 at 14:24

            Here is fill channel approach.

            Source https://stackoverflow.com/questions/65818690

            QUESTION

            How to separate human body from background in an image
            Asked 2021-Jan-10 at 18:25

            I have been trying to separate the human body in an image from the background, but all the methods I have seen don't seem to work very well for me.

            I have collected the following images;

            • The image of the background
            • The image of the background with the person in it.

            Now I want to cut out the person from the background. I tried subtracting the image of the background from the image with the person using res = cv2.subtract(background, foreground) (I am new to image processing).

            Background subtraction methods in opencv like cv2.BackgroundSubtractorMOG2() and cv2.BackgroundSubtractorMOG2() only works with videos or image sequence and contour detection methods I have seen are only for solid shapes.

            And grabCut doesn't quite work well for me because I would like to automate the process.

            Given the images I have (Image of the background and image of the background with the person in it), is there a method of cutting the person out from the background?

            ...

            ANSWER

            Answered 2021-Jan-01 at 13:51

            Since it is very easy to find dataset consist a lot of human body, I suggest you to implement neural network segmentation tecniques to extract human body perfectly. Please check this link to see similar example.

            Source https://stackoverflow.com/questions/65519304

            QUESTION

            Outline of pixels after detecting object (without convex hull)
            Asked 2020-Oct-09 at 16:12

            The idea is to use grabcut (OpenCV) to detect the image inside a rectangle and create a geometry with Direct2D.

            My test image is this:

            After performing the grab cut, resulting in this image:

            the idea is to outline it. I can use an opacity brush to exclude it from the background but I want to use a geometric brush in order to be able to append/widen/combine geometries on it like all other selections in my editor (polygon, lasso, rectangle, etc).

            If I apply the convex hull algorithm to the points, I get this:

            Which of course is not desired for my case. How do I outline the image?

            After getting the image from the grabcut, I keep the points based on luminance:

            ...

            ANSWER

            Answered 2020-Oct-09 at 16:12

            For anyone interested, the solution is OpenCV contours. Working example here.

            Source https://stackoverflow.com/questions/64243814

            QUESTION

            AttributeError: module 'cv2.cv2' has no attribute 'samples'
            Asked 2020-May-18 at 09:43

            After cloning the GitHub repo of OpenCV, I am trying to run grabcut.py but I am getting error : Traceback (most recent call last): File "grabcut.py", line 114, in img = cv.imread(cv.samples.findFile(filename)) AttributeError: module 'cv2.cv2' has no attribute 'samples'

            Here is the link to the file: https://github.com/opencv/opencv/blob/master/samples/python/grabcut.py

            ...

            ANSWER

            Answered 2019-Mar-12 at 07:18

            samples submodule is available in opencv-python version 4.0.0.21. Use pip install to install that specific version.

            Source https://stackoverflow.com/questions/54972811

            QUESTION

            Why does a right click open a drop down menu in my OpenCV imshow() window?
            Asked 2020-May-16 at 17:55

            I am trying to run the OpenCV Grabcut Sample on my system:

            • OpenCV version 4.1.0
            • Python version 3.6.8
            • IDLE version 3.6.8
            • Ubuntu 18.04.2

            This is the build information from cv2.getBuildInformation():

            In the Grabcut Sample script, I need to 'draw a rectangle around the object using the right mouse button.' For some reason, a drop down menu appears when I click the right mouse button (this is me clicking and holding the right mouse button):

            This didn't happen before, but since I reformatted my computer and reinstalled OpenCV I get this drop down menu. The imshow window looks different too. I tried installing lots of video codec packages (from this tutorial), but that didn't help.

            This drop down menu interferes with the mouse callback functions. How can I get rid of this drop down menu?

            I installed OpenCV with the command pip3 install opencv-contrib-python. I knew I was missing some packages so I tried to install (but failed - 'couldn't find any package by regex...') these packages from this tutorial:

            ...

            ANSWER

            Answered 2019-Jun-18 at 20:12

            You're using the Qt highgui backend, which looks like it forces the right-click context menu without the ability to disable it without recompilation of opencv. If you didn't see it before, it's likely you were using a different backend.

            If you prefer using Qt and don't mind altering the opencv source slightly and rebuilding, it looks like changing the DefaultViewPort::contextMenuEvent() method in file modules/highgui/src/window_QT.cpp to skip building the menu and just returning will probably work (or else have it optionally build the menu due to some flag that you add). Currently, the Qt highgui backend auto-creates the menu using whatever actions are available in the regular menu.

            Here's a link to the method in the current opencv master branch as of 2019-06-18:

            https://github.com/opencv/opencv/blob/1d2ef6b2a14fd5f80277d64b14e4a9a2faddc7d8/modules/highgui/src/window_QT.cpp#L2697

            which has this code:

            Source https://stackoverflow.com/questions/56623487

            QUESTION

            Python OpenCV: Crop image to contents, and make background transparent
            Asked 2020-Apr-02 at 17:05

            I have the following image:

            I want to crop the image to the actual contents, and then make the background (the white space behind) transparent. I have seen the following question: How to crop image based on contents (Python & OpenCV)?, and after looking at the answer, and trying it, I got the following code:

            ...

            ANSWER

            Answered 2020-Apr-02 at 17:05

            Here is one way to do that in Python/OpenCV.

            As I mentioned in my comment, your provided image has a white circle around the cow and then a transparent background. I have made the background fully white as my input.

            Input:

            Source https://stackoverflow.com/questions/60989084

            QUESTION

            Python OpenCV doesn't give same output at the same image
            Asked 2020-Mar-31 at 21:15

            I'm trying to create a program that checks if 2 images are the same. I have the following code which gets executed with both the images:

            ...

            ANSWER

            Answered 2020-Mar-31 at 21:15

            cv2.grabCut doesn't give deterministic results because the GrabCut algorithm uses built in randomness.

            According to Wikipedia:

            This is used to construct a Markov random field over the pixel labels...

            You may avoid randomness by resetting the seed of the random generator of OpenCV before executing cv2.grabCut:

            Source https://stackoverflow.com/questions/60954921

            QUESTION

            Is it possible to paste an image on top of another in OpenCV?
            Asked 2020-Mar-30 at 22:00

            I am fairly new to OpenCv and am creating a program that will segment a shoe from its background using GrabCut algorithm, then I want to paste the shoe onto a white background but I am struggling at that part.

            I tried cv2.add() to add the two images together but the two images have to be the same size and I can't guarantee that since the program prompts the user to upload the image.

            I have also tried whiteBgImg = 255 - grabCutImg to make the background white where the shoe isn't but it seems to affect the final image which is a problem as I need to perform feature detection and matching on the image.

            Thank you in advance for the advice! :)

            Original image: Original Shoe

            Final image (after grabcut and whiteBgImg = 255 - grabCutImg applied): Grabcut Shoe

            ...

            ANSWER

            Answered 2020-Mar-30 at 19:19

            If you want to put one image in front of the other image, you can do this as follows:

            Source https://stackoverflow.com/questions/60937583

            QUESTION

            How to change black color to transparent from a bitmap Mat?
            Asked 2020-Feb-13 at 14:43

            Can the mat or umat have null values in the middle? I need it to behave like .png format. If not, how can I achieve this purpose? Mat and Umat act like a rectangle image to me.

            I have tried rectangle copy method, grabcut method, but none of the method works right.

            I started the code as below:

            ...

            ANSWER

            Answered 2019-Apr-03 at 10:04
            ///////////////// add black as transparency /////////////////
                    Bitmap bmpUImage = new Bitmap(plotBox_Method.Image);
            
                    Mat output = new Mat();
                    Mat Shading_Image = new Image(bmpUImage).Mat;
            
                    // puting a black rectangle for transparent area later
                    Shading_Image.CopyTo(output);
                    CvInvoke.Rectangle(output, mask_rect, new MCvScalar(0,0,0), -1);
            
                    Mat imageMat = output;
                    Mat finalMat = new Mat(imageMat.Rows, imageMat.Cols, Emgu.CV.CvEnum.DepthType.Cv8U, 4);
                    Mat tmp = new Mat(imageMat.Rows, imageMat.Cols, Emgu.CV.CvEnum.DepthType.Cv8U, 1);
                    Mat alpha = new Mat(imageMat.Rows, imageMat.Cols, Emgu.CV.CvEnum.DepthType.Cv8U, 1);
            
                    CvInvoke.CvtColor(imageMat, tmp, Emgu.CV.CvEnum.ColorConversion.Bgr2Gray);
                    CvInvoke.Threshold(tmp, alpha, 0, 255, Emgu.CV.CvEnum.ThresholdType.Binary);
            
                    CvInvoke.Imshow("alpha", alpha);
            
                    VectorOfMat rgb = new VectorOfMat(3);
            
                    CvInvoke.Split(imageMat, rgb);
            
                    Mat[] rgba = { rgb[0], rgb[1], rgb[2], alpha };
            
                    VectorOfMat vector = new VectorOfMat(rgba);
            
                    CvInvoke.Merge(vector, finalMat);
            
                    imgPlot.Image = finalMat.ToImage().ToBitmap(); 
                    ///////////////// end of add black as transparency /////////////////
            

            Source https://stackoverflow.com/questions/55486889

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install grabcut

            You can download it from GitHub.
            You can use grabcut like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/CauldronDevelopmentLLC/grabcut.git

          • CLI

            gh repo clone CauldronDevelopmentLLC/grabcut

          • sshUrl

            git@github.com:CauldronDevelopmentLLC/grabcut.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link

            Consider Popular Computer Vision Libraries

            opencv

            by opencv

            tesseract

            by tesseract-ocr

            face_recognition

            by ageitgey

            tesseract.js

            by naptha

            Detectron

            by facebookresearch

            Try Top Libraries by CauldronDevelopmentLLC

            CAMotics

            by CauldronDevelopmentLLCC

            oh-brother

            by CauldronDevelopmentLLCPython

            cbang

            by CauldronDevelopmentLLCC++

            v8-3.14.5

            by CauldronDevelopmentLLCC++

            dockbot

            by CauldronDevelopmentLLCPython