Ask Your Question

Dr Dre's profile - activity

2018-03-09 07:57:06 -0500 received badge  Popular Question (source)
2018-01-24 11:05:30 -0500 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 -0500 received badge  Famous Question (source)
2016-12-14 21:13:05 -0500 received badge  Notable Question (source)
2016-11-22 14:34:58 -0500 received badge  Popular Question (source)
2016-05-18 08:41:13 -0500 asked a question webcam image capture focusing problem

Hi guys

I have written a basic code which captures an image from webcam using python 2.7 .

The code is as follows

import numpy
import cv2
cap = cv2.VideoCapture(0)
ret, frame = cap.read()
cv2.imshow('image',frame)
cap.release()
cv2.waitKey(0)
cv2.destroyAllWindows()

This code gives the correct output but my camera takes a few seconds to focus so i get a black or dim image as output instead of a bright proper focused image..

how can i correct this problem. I am using cv2 and python 2.7

2016-02-26 08:34:33 -0500 commented answer Extracting only blue from given image

Thank U @sturkmen

2016-02-26 08:33:54 -0500 commented answer Optimizing image processing code

Thank U....

2016-02-26 08:31:46 -0500 answered a question Extracting only blue from given image

http://docs.opencv.org/3.1.0/df/d9d/t...

This link helped me to find the solution

2016-02-26 08:30:27 -0500 answered a question Difference between thresholding function

Figured out that both are same

2016-02-19 12:51:57 -0500 asked a question Face Detection Using Image Processing [Approach]

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

2016-02-16 11:10:35 -0500 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:55:57 -0500 commented question Extracting only blue from given image

@sturkmen

In the code that u have provided

lower_blue = np.array([110,50,50])
upper_blue = np.array([130,255,255])

is this range bgr value of hsv image ??? or hsv value

2016-02-15 18:47:41 -0500 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 -0500 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 -0500 received badge  Organizer (source)
2016-02-15 11:30:52 -0500 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 -0500 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

2016-02-15 11:18:15 -0500 asked a question Extracting only blue from given image

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

2016-02-13 20:16:07 -0500 asked a question Colour Detection During Line Following

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

2016-02-07 09:58:01 -0500 received badge  Self-Learner (source)
2016-02-06 09:09:06 -0500 marked best answer Contour Numbering Doubt

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(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(img,contours,-1,(0,255,0),3)
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

When I write

cv2.drawContours(img,contours,0,(0,255,0),3)

I want contour to be drawn around black box

When I write

cv2.drawContours(img,contours,1,(0,255,0),3)

I want contour to be drawn around orange box

When I write

cv2.drawContours(img,contours,2,(0,255,0),3)

I want contour to be drawn around green box

and so on...............

But this doesn't happen . The system assigns contour number randomly as a result it is very difficult for me to get a particular contour that i want.

Why is the system numbering the contours randomly? Is there any concept about contouring that i have got wrong and is there any workaround so that i can get my contouring in the image in the manner as I discussed above.

I am using python and cv2

2016-02-06 08:58:00 -0500 marked best answer 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.

2016-02-06 08:49:07 -0500 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 -0500 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 -0500 commented question How to read center pixel color

Thank u that solves the problem

2016-02-06 08:33:21 -0500 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 -0500 commented answer How to read center pixel color

@berak Sir check out the updated question

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

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

2016-02-05 11:36:45 -0500 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 -0500 commented question Problem in removing particular colors from the given image

Thank U Guys

2016-02-04 10:16:18 -0500 commented answer Contour Numbering Doubt

Thank U @StevenPuttemans Will try to understand the information present in the link provided by u