Ask Your Question

Bazmundi's profile - activity

2020-03-12 11:30:24 -0600 received badge  Famous Question (source)
2020-01-10 16:48:56 -0600 received badge  Notable Question (source)
2019-12-27 10:33:13 -0600 received badge  Student (source)
2018-09-08 22:41:09 -0600 received badge  Famous Question (source)
2018-07-21 07:58:52 -0600 received badge  Popular Question (source)
2018-03-06 01:16:05 -0600 received badge  Notable Question (source)
2018-01-16 07:25:28 -0600 received badge  Popular Question (source)
2017-11-02 06:50:32 -0600 received badge  Self-Learner (source)
2017-06-11 20:49:26 -0600 received badge  Self-Learner (source)
2017-06-11 01:55:43 -0600 commented answer How do I convert uint8 to CV_8UC1 in OpenCV 3.2 Python?

Yep. I had worked this out in the background but I am still appreciative of the response by #berak as it also helps me understand why the code fixed the problem.

2017-06-11 01:50:45 -0600 received badge  Supporter (source)
2017-06-10 22:27:04 -0600 asked a question How do I convert uint8 to CV_8UC1 in OpenCV 3.2 Python?

The code is the following:

import numpy as np
import cv2
import time
from matplotlib import pyplot as plt

cv2.namedWindow( "Left", cv2.WINDOW_AUTOSIZE );
cv2.namedWindow( "Right", cv2.WINDOW_AUTOSIZE );

cam1 = cv2.VideoCapture(1)
cam1.set(cv2.CAP_PROP_FRAME_WIDTH,384)
cam1.set(cv2.CAP_PROP_FRAME_HEIGHT,216)

cam2 = cv2.VideoCapture(2)
cam2.set(cv2.CAP_PROP_FRAME_WIDTH,384)
cam2.set(cv2.CAP_PROP_FRAME_HEIGHT,216)

stereo = cv2.StereoBM_create(numDisparities=16, blockSize=15)


while(True):

    # Capture frame-by-frame

    ret, frame1 = cam1.read()

    ret, frame2 = cam2.read()


    # Display the resulting frame
    cv2.imshow("Left",frame1)  
    cv2.imshow("Right",frame2)  

    disparity = stereo.compute(frame1,frame2) # kaput as it wants CV_8UC1 matrix
    plt.imshow(disparity,'gray')
    plt.show()

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# When everything done, release the capture
cam1.release()
cam2.release()
cv2.destroyAllWindows()

Computing disparity is kaput as the image frame appears to be uint8 while the disparity computation wants CV_8UC1. Examples I have found to do the conversion are either in C++ or not in OpenCV 3.2 Pythonesque.

What is the conversion approach for uint8 to CV_8UC1 in OpenCV 3.2 Python please?

Cheers, A

2017-06-10 21:38:44 -0600 commented question Why do I get an interaction between different cameras?

Self Answer (given I don't have kudos to add self answer yet) is:

cam1 = cv2.VideoCapture(1)
cam1.set(cv2.CAP_PROP_FRAME_WIDTH,384)
cam1.set(cv2.CAP_PROP_FRAME_HEIGHT,216)

cam2 = cv2.VideoCapture(2)
cam2.set(cv2.CAP_PROP_FRAME_WIDTH,384)
cam2.set(cv2.CAP_PROP_FRAME_HEIGHT,216)

It seems the USB channel gets choked (it is only USB 2.0) so one needs to right size the images so that two cameras can work off that single port. Full code solution tomorrow or next day once my kudos limit expires.

2017-06-10 20:22:14 -0600 commented question Why does faceCascade.detectMultiScale abort on call?

DOH. Answer is make sure you set the path to the xml haarcascade descriptor. The error is not very descriptive but it turns out it means there was no xml file at file path provided when running code.

2017-06-10 20:05:33 -0600 asked a question Why does faceCascade.detectMultiScale abort on call?

The code is:

import cv2
import sys

cascPath = sys.argv[1]
faceCascade = cv2.CascadeClassifier(cascPath)

video_capture = cv2.VideoCapture(1)

while True:
    # Capture frame-by-frame
    ret, frame = video_capture.read()

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    faces = faceCascade.detectMultiScale(
        gray,
        scaleFactor=1.1,
        minNeighbors=5,
        minSize=(30, 30),
        flags=cv2.CASCADE_SCALE_IMAGE
    )

    # Draw a rectangle around the faces
    for (x, y, w, h) in faces:
        cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)

    # Display the resulting frame
    cv2.imshow('Video', frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()

Code was from https://realpython.com/blog/python/fa...

The original code did not work because of deprication of cv2.cv.CV_HAAR_SCALE_IMAGE which is replaced with cv2.CASCADE_SCALE_IMAGE from guidance at https://stackoverflow.com/questions/4...

However, cv::CascadeClassifier::detectMultiScale causes exception with assertion (!empty()) at cascadedetect.cpp line 1681

I am using windoze 10, OpenCV 3.2, Python 2.7.9 64bit (stackless)

Any ideas please? It is a fresh install of OpenCV binaries.

Cheers, B

2017-06-10 05:06:35 -0600 received badge  Editor (source)
2017-06-10 04:48:34 -0600 asked a question Why do I get an interaction between different cameras?

Code is:

import numpy as np
import cv2

cam1 = cv2.VideoCapture(1)
cam2 = cv2.VideoCapture(2)

cv2.namedWindow( "Left", cv2.WINDOW_AUTOSIZE );
cv2.namedWindow( "Right", cv2.WINDOW_AUTOSIZE );

while(True):
    # Capture frame-by-frame
    ret, frame1 = cam1.read()
    ret, frame2 = cam2.read()



    # Display the resulting frame
    cv2.imshow('Left',frame1)  # code line works
    cv2.imshow('Right',frame2)  # code line hangs



    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# When everything done, release the capture
cam1.release()
cam2.release()
cv2.destroyAllWindows()

Problem is that code hangs on imshow of frame 2 if and only if frame1 was read. That is, if I delete the code line that hangs then code runs. If I delete code line that hangs but change frame used to frame2 then code runs. So, when both camx.read() are called it seems fine, it is only hanging when the two imshow are being called.

Error reported is:

Traceback (most recent call last):
  File "D:\python\webcam.py", line 19, in <module>
    cv2.imshow('Right',frame2)  # hangs
error: C:\build\master_winpack-bindings-win64-vc14-static\opencv\modules\highgui\src\window.cpp:304: error: (-215) size.width>0 && size.height>0 in function cv::imshow

Quirk also is that the following works unless I swap the order of the VideoCapture(x):

cv2.imshow('Left',frame1)  # code line works
cv2.imshow('Right',frame1)  # code line still works (but using same buffer)

While the following does not work unless I swap the order of the VideoCapture(x):

cv2.imshow('Left',frame2)  # code line not longer works (using second buffer)
cv2.imshow('Right',frame2)  # ditto

I am using a stereo camera which works as two separate cameras. Camera works with other software. Running OpenCV3.2 on 64bit Python 2.7.9 (stackless).

Another couple of things. Coding up to using only one camera and changing the index for the camera, to select either one or the other camera, works.

I found, by experimenting, that releasing camera 1 allow camera 2 to read a buffer BUT alternatingly creating/then releasing cameras did not work - there didn't seem to be an alternate way to do this with the python.

So, it appears, that something more fiddly than creating cam1 and cam2 is required as the cameras seem to share something that does not allow them to be active at same time.
Cheers, B

2017-06-10 04:38:32 -0600 commented answer createStereoBM, does it or does it not exist?

Cheers, that sorted it, now I go onto next problem ;)

2017-06-09 23:28:37 -0600 asked a question createStereoBM, does it or does it not exist?

The usual drill, I downloaded and installed OpenCV 3.2 on windows, moved the python hooks into site-packages, ran a few simple examples to find reports such as:

Traceback (most recent call last): File "D:\python\webcam.py", line 10, in <module> stereo = cv2.createStereoBM(numDisparities=16, blockSize=15) AttributeError: 'module' object has no attribute 'createStereoBM'

Example from: http://opencv-python-tutroals.readthe...

Now evidence is createStereoBM does exist given: http://docs.opencv.org/3.0-beta/modul...

Is there something missing in the import statement for cv2 perhaps?

I am running on windows 10 via python 2.7.9 (stackless).

Cheers, B

2017-06-09 23:28:36 -0600 asked a question cv2 has noocv2.createStereoBM, why not as it is actually valid?

Usual drill, a web based example at opencv python tutorials.

With a brand new spanking install of OpenCV3.2 I try the example at:

http://opencv-python-tutroals.readthe...

The following line fails:

stereo = cv2.createStereoBM(numDisparities=16, blockSize=15)

Problem is createStereoBM is not a recognised module (apparently) despite being documented at:

http://docs.opencv.org/3.0-beta/modul...

So, what would be the problem with a fresh install of OpenCV 3.2 please?