Ask Your Question

Dr Dre's profile - activity

2020-11-13 06:55:56 -0600 received badge  Popular Question (source)
2020-02-01 12:15:25 -0600 received badge  Notable Question (source)
2019-10-25 13:57:16 -0600 received badge  Popular Question (source)
2018-03-09 07:57:06 -0600 received badge  Popular Question (source)
2018-01-24 11:05:30 -0600 marked best answer Resizing the output window of imshow function

Hi Guys

I have an image with 6000 * 6000 pixels as shown

link of image

When I run the following code

    import cv2
    img = cv2.imread('Test.jpg')
    cv2.imshow('image',img)
    cv2.waitKey(0)
    cv2.destroyAllWindows()

It wont display the entire image in the output but a part of it .

How do i make the imshow function display the entire image in its output window ?

I am using open cv2 and python 2.7

2017-02-06 09:08:20 -0600 received badge  Famous Question (source)
2016-12-14 21:13:05 -0600 received badge  Notable Question (source)
2016-11-22 14:34:58 -0600 received badge  Popular Question (source)
2016-02-26 08:33:54 -0600 commented answer Optimizing image processing code

Thank U....

2016-02-16 11:10:35 -0600 asked a question Optimizing image processing code

Hi guys

I am working on image processing project which involves line following and also traffic sign detection.

If traffic sign displays stop, line follower robot should stop . other wise it follows the line

i want to perform the above two operations of line follower and traffic signal detection concurrently.

What should be my approach in doing so

i am using raspberry pi b+ and python.. how can i optimize image processing operation

2016-02-15 18:47:41 -0600 commented question Freeing Ram by deleting image matrix

what if i want to delete it manually . What syntax shalll i use

2016-02-15 18:46:50 -0600 commented question Difference between thresholding function

output image has no difference. but there is little bit change in syntax

2016-02-15 11:33:00 -0600 received badge  Organizer (source)
2016-02-15 11:30:52 -0600 asked a question Freeing Ram by deleting image matrix

I have a simple code

import cv2
import numpy as np

Image = cv2.imread('blue.jpg')

Threshold = np.zeros(Image.shape, np.uint8) 
cv2.threshold(Image, 121, 255,   cv2.THRESH_BINARY, Threshold) 
cv2.imshow("WindowName", Threshold )

cv2.waitKey(0) 
cv2.destroyAllWindows()

I want to delete matrix

"Image" from memeory i.e clear memory to save space in ram

How can i acheive this

2016-02-15 11:22:01 -0600 asked a question Difference between thresholding function

Hi Guys

I have two set of codes for thresholding

Code 1

import cv2
import numpy as np

Image = cv2.imread('blue.jpg')

Threshold = np.zeros(Image.shape, np.uint8)
cv2.threshold(Image, 121, 255, cv2.THRESH_BINARY, Threshold)
cv2.imshow("WindowName", Threshold )

cv2.waitKey(0)
cv2.destroyAllWindows()

and

Code 2

 import cv2
import numpy as np

Image = cv2.imread('blue.jpg')


ret, thresh = cv2.threshold(Image, 121, 255, cv2.THRESH_BINARY)
cv2.imshow("WindowName", thresh )

cv2.waitKey(0)
cv2.destroyAllWindows()

What is the difference between these two thresh functions

Hi Guys

I Have an input image as

image description

I Have used the following code to brighten blue

import cv2
import numpy as np

Image = cv2.imread('blue.jpg')

Threshold = np.zeros(Image.shape, np.uint8)
cv2.threshold(Image, 121, 255, cv2.THRESH_BINARY, Threshold)
cv2.imshow("WindowName", Threshold )

cv2.waitKey(0)
cv2.destroyAllWindows()

The output of this code is

image description

I want to extract only the blue portion of this image and eliminate the remaining ..

The output should be anything like these images

image description

image description

image description

I am using python2.7 with cv2

Hi Guys

I am working on a line follower bot which follows black line on white background The code is something like this

import numpy as np
import cv2
cap = cv2.VideoCapture(0)
try:
    while(1):
        ## Read the image
        ret, img = cap.read()
        #cv2.imshow('image',img)
        img = img[160:320,:,:]

        gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
        ret,thresh = cv2.threshold(gray,170,255,cv2.THRESH_BINARY_INV)
        #Applying Dilation Morphological Operation To Dilate the image 
        kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3,3))
        dilation = cv2.dilate(thresh, kernel, iterations = 5)    
        #Apllying Gaussian Bluring Algorithm to reduce the number of contours
        blur3 = cv2.medianBlur (dilation,5)
        i = 0
        contours, hierarchy = cv2.findContours(blur3,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
        cv2.drawContours(img,contours,-1,(0,255,0),3)
        cv2.imshow('image',img)

        M = cv2.moments(contours[i])
        cx = int(M['m10']/M['m00'])
        cy = int(M['m01']/M['m00'])


        if cx < 190:                                 
               print "LEFT"
        if cx > 450:
              print "RIGHT "                    
       if ((cx > 189) & (cx < 449)):
              print "FRONT"
finally:
            cap.release()
    cv2.destroyAllWindows()

I want to also detect blue and red color while the bot is following the line using the same camera.

I tried reading center pixel of the centroid center_px = img[cy,cx]

But reading just one pixel dosent prove efficient in determining the color.

So is there any other approach to do this

I am using python2.7 with cv2

Hi guys

I am working on a project which involves detection of human faces.

How can i perform this task?

What algorithms should i use?

What should be my approach in performing this task ??

I will be using python 2.7 with cv2

Hi Guys

I Have an image as shown

image description

This is a simple code to create contour around the rectangular boxes.

import numpy as np
import cv2
img = cv2.imread('Image.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(gray,100,255,cv2.THRESH_BINARY_INV)
contours, hierarchy = cv2.findContours ...
(more)
2016-02-07 09:58:01 -0600 received badge  Self-Learner (source)
2016-02-06 08:49:07 -0600 answered a question Problem in removing particular colors from the given image

I Filtered out only sky blue color, Pink Color, Orange and Green Color using masking function separetely and added the images to get an image containing only the 4 colors

then by converting bgr to gray and thresholding i could draw the contours

Thank U Every one for ur help and support

image description

2016-02-06 08:44:34 -0600 commented question How to read center pixel color

plz update ur answer so that it might help anyone having similar problem

2016-02-06 08:44:01 -0600 commented question How to read center pixel color

Thank u that solves the problem

2016-02-06 08:33:21 -0600 commented question How to read center pixel color

@FooBar @berak Important point to be noted

the center_px value is showing as 255 255 255 rather than 0,127,255

Here is the error .. But i dont know why it is doing so .

2016-02-06 08:25:27 -0600 commented answer How to read center pixel color

@berak Sir check out the updated question

2016-02-05 19:56:45 -0600 commented question How to read center pixel color

@FooBar , the code has been updated .. Check it out

2016-02-05 11:36:45 -0600 asked a question How to read center pixel color

Hi guys

This is my image

I want to read the centre pixel value of the following contour an output the color as Orange. But i tend to get an error as

if (center_px == ORANGE):
    ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

The input image is

image description

import numpy as np
import cv2
img = cv2.imread('New Bitmap Image.bmp')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(gray,100,255,cv2.THRESH_BINARY)
contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(img,contours,-1,(0,0,255),19)

for i in range(0,len(contours)):
    M = cv2.moments(contours[i])
    cx = int(M['m10']/M['m00'])
    cy = int(M['m01']/M['m00'])
    print "Centroid = ", cx, ", ", cy

    center_px =  img[cx,cy]
    print center_px
    ORANGE = (0,127,255)

    if (center_px == ORANGE):
            print "Orange"

I am using pyhton and cv2

Update

As suggested by @berak I have modified the code as

import numpy as np
import cv2
img = cv2.imread('New Bitmap Image.bmp')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(gray,190,255,cv2.THRESH_BINARY_INV)
cv2.imshow("windows1",thresh)
contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(img,contours,-1,(0,0,255),2)
cv2.imshow("windows",img)
print len(contours)
for i in range(0,len(contours)):
    M = cv2.moments(contours[i])
    cx = int(M['m10']/M['m00'])
    cy = int(M['m01']/M['m00'])
    print "Centroid = ", cx, ", ", cy
    center_px = np.array([4,3,2],dtype=np.uint8)

    ORANGE = (0,127,255)


    center_px =  img[cx,cy]
    print center_px

    if ((center_px == ORANGE).all()):
        print "Orange"
    else:
        print "Not Orange"




cv2.waitKey(0)
cv2.destroyAllWindows()

The output is

1
Centroid =  146 ,  94
[255 255 255]
Not Orange

It shows not orange even though the image is orange color .What is it that i am doing wrong ????

2016-02-05 11:27:35 -0600 commented question Problem in removing particular colors from the given image

Thank U Guys

2016-02-04 10:13:13 -0600 commented question Problem in removing particular colors from the given image

What procedure should i follow next sir @StevenPuttemans

2016-02-04 08:47:55 -0600 edited question Problem in removing particular colors from the given image

Hi Guys I have the following image

Input Image

I want to know if there is any method which basically removes black and blue box from the image and the final image contains only orange , green pink and light blue box i.e. I want my output image to be displayed as

Output Image

I am using python 2.7 with cv2

Update

Following the suggestion give by @StevenPuttemans

I converted my given image to HSV using following code

img = cv2.imread('Image.jpg')
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
cv2.imshow('hsv',hsv)

I got output as

Intermediate Output

What procedure should i follow next to get my output as shown in 2nd image.