Ask Your Question

bb12jo's profile - activity

2016-08-26 12:40:07 -0500 received badge  Enthusiast
2016-08-25 18:07:31 -0500 asked a question How to set webcam codec in OpenCV 3.1.0 Python?

I have a problem with my webcams using the uncompressed YUYV codec in OpenCV Python which makes it so that I have horrible frame rates. I would like to set the codec to MJPG, but I can't seem to figure out how. Here is what I have tried(along with variations of it)

import cv2 #Opencv 3.1.0
import matplotlib.pyplot as plt
import numpy as np
vid = cv2.VideoCapture(0)
vid.set(6, cv2.CV_FOURCC('M','J', 'P', 'G'))#Should set the codec, but it doesn't

while True:
    _, img = vid.read()

    cv2.imshow('image', img)

    k = cv2.waitKey(5) & 0xFF
    if k == 27:
        break

vid.release()
cv2.destroyAllWindows()

When I run it, I get cv2 has no attribute to CV_FOURCC. I have been using this as a reference, but it doesn't really explain what I am supposed to pass in after I input the 6 in the vid.set(). I have the cv2.CV_FOURCC, but I just guessed that is what it wanted. Any help would be greatly appreciated!

2016-07-21 22:05:57 -0500 received badge  Scholar (source)
2016-07-21 22:05:56 -0500 received badge  Supporter (source)
2016-07-20 17:03:02 -0500 commented answer How to remove unwanted corners in images?

Nevermind, fixed the issue. Thanks!!!!!!

2016-07-16 22:41:09 -0500 commented question How to remove unwanted corners in images?

Thanks for the heads up! Fixed.

2016-07-16 22:40:19 -0500 received badge  Editor (source)
2016-07-16 22:27:50 -0500 asked a question How to remove unwanted corners in images?

Hi,

I am trying to rid of the corners in an image where I will be combining that image with three other images. The corners have been blocking a part of the image next to it. The images are in the shape of a trapezoid because I used the perspective shift in opencv. Here is the single image:C:\fakepath\image.png and here is the attempt at combing them: C:\fakepath\blank.png

Here is my code:

import cv2
import numpy as np
import matplotlib.pyplot as plt
def autocrop(image, threshold=0):
#Crops the bottom part of the image, but not the corners
    if len(image.shape) == 3:
        flatImage = np.max(image, 2)
    else:
        flatImage = image
    assert len(flatImage.shape) == 2

    rows = np.where(np.max(flatImage, 0) > threshold)[0]
    if rows.size:
        cols = np.where(np.max(flatImage, 1) > threshold)[0]
        image = image[cols[0]: cols[-1] + 1, rows[0]: rows[-1] + 1]
    else:
        image = image[:1, :1]

    return image
img1 = cv2.imread("testBird.png", 1) #cv.IMREAD_COLOR


image = np.zeros((700, 700, 4), np.uint8)
src = np.array([[0,200],[480,200],[480,360],[0,360]],np.float32)
dst = np.array([[0,0],[480,0],[300,210],[180,210]],np.float32)
cvters = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
t, s = cv2.threshold(cvters, 1, 255, cv2.THRESH_BINARY)
rs, gs, bs = cv2.split(img1)
finals = cv2.merge((rs, gs, bs, s))

M = cv2.getPerspectiveTransform(src, dst)
warp = cv2.warpPerspective(finals.copy(), M, (480, 360))



two = warp.copy()


three = warp.copy()
four = warp.copy()
image[:warp.shape[0], 100:warp.shape[1]+100]= warp
twoR = cv2.getRotationMatrix2D((two.shape[1]/2,two.shape[0]/2),90,1)
twoD = cv2.warpAffine(two,twoR,(two.shape[1],two.shape[0]))

twoD = autocrop(twoD)

image[100:twoD.shape[0]+100, 60:twoD.shape[1]+60]= twoD

cv2.imwrite('blank.png', image)

I have tried making the pixels transparent using the alpha channel, but I never got it to work(You can still see that I have the alpha channel split and merged). I have tried cropping which works for the bottom half of the image, but not the corners. I have tried doing a contour crop but that didn't work although I felt like I might have done something wrong. I have tried to fix this issue for over a week now so any help would be greatly, greatly appreciated!