Ask Your Question

hernancrespo's profile - activity

2020-01-24 15:09:46 -0500 commented question cv2.cvtColor causes to stop Python

Pyton has stopped working

2020-01-24 14:55:30 -0500 commented question cv2.cvtColor causes to stop Python

what do you mean by input image? because fg is valid

2020-01-24 14:20:35 -0500 asked a question cv2.cvtColor causes to stop Python

cv2.cvtColor causes to stop Python I am using PyQT,Python and OpenCV. I want to find contours. So i need to convert imag

2020-01-24 13:56:36 -0500 marked best answer How to set and get brightness of camera using PyQt

Hi, I have been trying to set and get brightness value of webcam when i press button. I want to set brightness then read it. When i read brightness it prints 0.0 which is not the actual value. And set_brightness has no effect

Here is my full code

main.py

from PyQt5.QtWidgets import QApplication
from views import UI_Window
from models import Camera

if __name__ == '__main__':

    camera = Camera(0)
    app = QApplication([])
    start_window = UI_Window(camera)
    start_window.show()
    app.exit(app.exec_())

models.py

import cv2


class Camera:

    def __init__(self, cam_num):

        self.cap = cv2.VideoCapture(cam_num)
        self.cam_num = cam_num

    def open(self, width=640, height=480, fps=30):
        self.cap.set(5, fps)  #set FPS
        self.cap.set(3, width)  
        self.cap.set(4, height)
        return self.cap.isOpened()

    def read(self):
        rval, frame = self.cap.read()
        frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
        return frame

    def get_brightness(self):
        return self.cap.get(cv2.CAP_PROP_BRIGHTNESS)

    def set_brightness(self, value):
        self.cap.set(cv2.CAP_PROP_BRIGHTNESS, value)

views.py

from PyQt5.QtCore import QThread, QTimer
from PyQt5.QtWidgets import QLabel, QWidget, QPushButton, QVBoxLayout, QApplication, QHBoxLayout, QMessageBox,  QMainWindow
from PyQt5.QtGui import QPixmap, QImage
from models import Camera


class UI_Window(QWidget):

    def __init__(self, cam_num):
        super().__init__()
        self.cam_num = cam_num
        self.cam_num.open()
        # Create a timer.
        self.timer = QTimer()
        self.timer.timeout.connect(self.nextFrameSlot)
        self.timer.start(1000. / 24)
        layout = QVBoxLayout()
        button_layout = QHBoxLayout()
        btnCamera = QPushButton("Print Brightness")
        btnCamera.clicked.connect(self.print_brightness)
        button_layout.addWidget(btnCamera)
        layout.addLayout(button_layout)
        # Add a label
        self.setLayout(layout)

    def nextFrameSlot(self):
        frame = self.cam_num.read()
        if frame is not None:
            image = QImage(frame, frame.shape[1], frame.shape[0], QImage.Format_RGB888)
            self.pixmap = QPixmap.fromImage(image)

    def print_brightness(self):
         self.cam_num.set_brightness(0.5)
         print(self.cam_num.get_brightness())
2020-01-24 06:11:08 -0500 asked a question How to set and get brightness of camera using PyQt

How to set and get brightness of camera using PyQt Hi, I have been trying to set and get brightness value of webcam when

2020-01-02 17:03:16 -0500 commented question How to remove some black parts from image

I tried hsv. How can i clip lower and higher part of my contour. İ hope to remove 20×10 pixel from top and remove 20x10

2020-01-02 17:02:48 -0500 commented question How to remove some black parts from image

I tried hsv. How can i clip lower and higher part of my contour. İ hope to remove 50 pixel from top and remove 5 pixel f

2020-01-02 16:52:25 -0500 commented question How to remove some black parts from image

Thanks, are there any proposed method?

2020-01-02 16:34:53 -0500 edited question How to remove some black parts from image

How to remove some black parts from image This is my frame. I would like to remove some black parts. I tried filter tho

2020-01-02 16:34:22 -0500 asked a question How to remove some black parts from image

How to remove some black parts from image This is my frame. I would like to remove some black parts. I tried filter thos

2019-12-30 17:53:47 -0500 asked a question How to find contours inside the biggest contour

How to find contours inside the biggest contour Hi, i can find biggest contour on a frame. I would like to find and plot

2019-12-26 15:10:38 -0500 edited question How to plot histogram of an area inside a contour

How to plot histogram of an area inside a contour Hi, i am using OpenCV and python. i can find the biggest contour i n

2019-12-26 09:54:38 -0500 marked best answer Unable to find and draw biggest contour

I want to find and draw biggest contour on a frame. i can find the contours. then i add these three lines to find biggest contour.

 c = max(contours, key = cv2.contourArea)
 x,y,w,h = cv2.boundingRect(c)
 cv2.rectangle(fg,(x,y),(x+w,y+h),(0,255,0),2

and i see an error message:

max() arg is an empty sequence

but when i run len(contours) i see a value as a result, contour is not empty. here is my code:

import cv2
import numpy as np
#capture.release()
cv2.destroyAllWindows()
capture = cv2.VideoCapture(1)
panel = np.zeros([100, 700], np.uint8)
cv2.namedWindow('panel')
def nothing(x):
    pass

cv2.createTrackbar('L - h', 'panel', 0, 179, nothing) #
cv2.createTrackbar('U - h', 'panel', 179, 179, nothing)

cv2.createTrackbar('L - s', 'panel', 0, 255, nothing)
cv2.createTrackbar('U - s', 'panel', 255, 255, nothing)

cv2.createTrackbar('L - v', 'panel', 0, 255, nothing)
cv2.createTrackbar('U - v', 'panel', 255, 255, nothing)

cv2.createTrackbar('S ROWS', 'panel', 0, 480, nothing) #start 
cv2.createTrackbar('E ROWS', 'panel', 480, 480, nothing) # end
cv2.createTrackbar('S COL', 'panel', 0, 640, nothing)
cv2.createTrackbar('E COL', 'panel', 640, 640, nothing)

while(True):

    ret, frame = capture.read()

    s_r = cv2.getTrackbarPos('S ROWS', 'panel')
    e_r = cv2.getTrackbarPos('E ROWS', 'panel')
    s_c = cv2.getTrackbarPos('S COL', 'panel')
    e_c = cv2.getTrackbarPos('E COL', 'panel')
    #print(frame.shape) = 480 , 640, 3 
    roi = frame[s_r: e_r, s_c: e_c]
    roi =  cv2.GaussianBlur(roi, (5, 5), 0) #sigma = 0
    hsv = cv2.cvtColor( roi, cv2.COLOR_RGB2HSV)    

    l_h = cv2.getTrackbarPos('L - h', 'panel')
    u_h = cv2.getTrackbarPos('U - h', 'panel')
    l_s = cv2.getTrackbarPos('L - s', 'panel')
    u_s = cv2.getTrackbarPos('U - s', 'panel')
    l_v = cv2.getTrackbarPos('L - v', 'panel')
    u_v = cv2.getTrackbarPos('U - v', 'panel')
    lower_green = np.array([l_h, l_s, l_v])
    upper_green = np.array([u_h, u_s, u_v])


    mask = cv2.inRange(hsv, lower_green, upper_green)
    mask_inv = cv2.bitwise_not(mask)

    bg = cv2.bitwise_and( roi,  roi, mask=mask)
    fg = cv2.bitwise_and( roi,  roi, mask=mask_inv)
    gray = cv2.cvtColor(fg, cv2.COLOR_BGR2GRAY)
    contours, hierarchy = cv2.findContours(gray,cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)

    for contour in contours:
        area = cv2.contourArea(contour)

        if area>20000:
            cv2.drawContours(fg, contours, -1, (0, 255, 0), 3)

    c = max(contours, key = cv2.contourArea)

    x,y,w,h = cv2.boundingRect(c)
    # draw the book contour (in green)
    cv2.rectangle(fg,(x,y),(x+w,y+h),(0,255,0),2)

    cv2.imshow('bg', bg)
    cv2.imshow('fg', fg)
    cv2.imshow('panel', panel)

    if cv2.waitKey(30) == 27: #siradaki frame'e gecmeden once 30 ms bekle
        break

capture.release()
cv2.destroyAllWindows()
2019-12-26 09:54:37 -0500 received badge  Scholar (source)
2019-12-24 17:06:33 -0500 asked a question Unable to find and draw biggest contour

Unable to find and draw biggest contour I want to find and draw biggest contour on a frame. i can find the contours. the

2019-12-21 01:10:57 -0500 received badge  Enthusiast
2019-12-20 13:25:11 -0500 commented question How to plot histogram of an area inside a contour

yes getting the area inside the contour, and plot the histogram of that area

2019-12-20 11:40:51 -0500 asked a question How to plot histogram of an area inside a contour

How to plot histogram of an area inside a contour Hi, i am using OpenCV and python. i have a contour. and i need histogr

2019-10-26 15:57:13 -0500 edited question How to implement plateau limit histogram equalization?

How to implement plateau limit histogram equalization? Hi everyone, I'm trying to implement this paper using MATLAB: htt

2019-10-26 15:56:47 -0500 received badge  Editor (source)
2019-10-26 15:56:47 -0500 edited question How to implement plateau limit histogram equalization?

How to implement plateau limit histogram equalization? Hi everyone, I'm trying to implement this paper using MATLAB: htt

2019-10-26 15:56:30 -0500 asked a question How to implement plateau limit histogram equalization?

How to implement plateau limit histogram equalization? Hi everyone, I'm trying to implement this paper using MATLAB: htt

2019-08-19 08:58:24 -0500 marked best answer How to use CV_FOURCC in version 4.1.0?

Hi, i am new with openCV. i'm trying to paste a code snippet from old versions. But i get lots of error.

 VideoWriter parlakVideo("videoParlak.avi", CV_FOURCC(‘M’, ‘P’, ‘4’, ‘2’), 20, boyut, true);
VideoWriter karanlikVideo("videoKaranlik.avi", CV_FOURCC(‘M’, ‘P’, ‘4’, ‘2’), 20, boyut, true);

here is my try:

VideoWriter parlakVideo("video.wmv", VideoWriter::fourcc ((‘M’, ‘P’, ‘4’, ‘2’), 20, boyut, true);
VideoWriter karanlikVideo("video.wmv", VideoWriter::fourcc((‘M’, ‘P’, ‘4’, ‘2’), 20, boyut, true);
2019-08-17 12:07:07 -0500 asked a question How to use CV_FOURCC in version 4.1.0?

How to use CV_FOURCC in version 4.1.0? Hi, i am new with openCV. i'm trying to paste a code snippet from old versions.