Ask Your Question

alex1306's profile - activity

2020-01-19 14:28:02 -0600 commented question How to group points using treshold?

@LBerger, @berak Thanks a lot!!

2020-01-19 13:39:33 -0600 asked a question How to group points using treshold?

How to group points using treshold? I have points list , from rectangle detector points_list = [(1853, 1054), (1900,

2018-06-10 19:11:28 -0600 received badge  Popular Question (source)
2017-05-31 23:16:43 -0600 received badge  Famous Question (source)
2016-06-10 07:13:43 -0600 commented answer What is MORPH_RECT parameters?

thanks for help!

2016-06-10 04:58:18 -0600 asked a question What is MORPH_RECT parameters?

What does it mean 21 and 10 parameters?

in

cv2.getStructuringElement(cv2.MORPH_RECT, (21, 21), (10, 10))

I can understand from docs.

2016-06-09 08:48:08 -0600 asked a question How to reduce noise using scharr filter?

I have code

#!/usr/bin/env python
# -*- coding= utf-8 -*-

import sys
import numpy as np
import cv2
import math

filename = sys.argv[1]
cap = cv2.VideoCapture(filename)
cap.set(cv2.cv.CV_CAP_PROP_POS_MSEC, 300000)
scale = 1
delta = 0
ddepth = cv2.CV_16S 
while(True):
       success, img = cap.read() 
       img = cv2.GaussianBlur(img,(3,3),0)       
       gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
       #Scharr filter
       scharr_grad_x = cv2.Scharr(gray,ddepth,1,0)
       scharr_grad_y = cv2.Scharr(gray,ddepth,0,1)
       scharr_abs_grad_x = cv2.convertScaleAbs(scharr_grad_x)   
       scharr_abs_grad_y = cv2.convertScaleAbs(scharr_grad_y)
       #remove noize after scharr filter
       ###scharr = np.hypot(scharr_abs_grad_x, scharr_abs_grad_y)
       ###mean = np.mean(scharr);
       ###scharr[scharr <= mean] = 0;
       scharr = cv2.add(scharr_abs_grad_x,scharr_abs_grad_y)
       cv2.imshow('scharr',scharr)
       if cv2.waitKey(1) & 0xFF == ord('q'):
            break


cap.release()
cv2.destroyAllWindows()

I want to reduce noise. I found something like this

   scharr = np.hypot(scharr_abs_grad_x, scharr_abs_grad_y)
   mean = np.mean(scharr);
   scharr[scharr <= mean] = 0;

Scharr.

image description

Scharr without noise I need.

image description

How can I implement it in my code?

2016-03-01 09:12:12 -0600 received badge  Notable Question (source)
2015-06-22 03:19:20 -0600 received badge  Popular Question (source)
2013-04-04 22:59:05 -0600 commented answer cv2.so missing after opencv installed

Thanks, I'll try it

2013-04-03 09:16:20 -0600 asked a question cv2.so missing after opencv installed

Today I tried to install opencv 2.4.4 to Ubuntu 12.10

The cv2.so missed, so import cv2 not work.

root@-:~# find / -name "cv.py"
/root/opencv-2.4.4/modules/python/src2/cv.py
root@-:~# find / -name "cv2.so"
root@-:~#

Python 2.7.3

Where is cv2.so ?

My setup steps look like

wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.4/OpenCV-2.4.4a.tar.bz2
tar -xjf OpenCV-2.4.4a.tar.bz2
cd opencv-2.4.4
mkdir release
cd release 
cmake -D CMAKE_BUILD_TYPE=RELEASE   -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON ..
make && make install
echo "/usr/local/lib" >> /etc/ld.so.conf.d/opencv.conf
ldconfig  
echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig" >> /etc/bash.bashrc
echo "export PKG_CONFIG_PATH" >> /etc/bash.bashrc
2013-04-03 09:10:13 -0600 received badge  Scholar (source)
2013-04-03 09:10:03 -0600 received badge  Supporter (source)
2013-03-25 07:43:28 -0600 commented answer How to detect semi transparent logo location on video?

I don't know how logo looks like before script start. Automate detection unchanged area on video without any templates.

2013-03-24 09:37:16 -0600 asked a question How to detect semi transparent logo location on video?

I make python script which auto detect stationary object on video (to simplify the idea - let it be a logo). I don't know logo location, because I can't see video. I start script in console. The idea of script - auto detection, not manual work. But I know that logo is on all video frames, and it located as usual in one of the coner.

I have small test videos:

https://dl.dropbox.com/u/100403694/1.mp4

https://dl.dropbox.com/u/100403694/2.mp4

https://dl.dropbox.com/u/100403694/3.mp4

https://dl.dropbox.com/u/100403694/4.mp4

All tests seems to be done except 2.mp4 Script can't detect logo on video 2.mp4

This is my script. Usage script.py 2.mp4

#!/usr/bin/env python
# -*- coding= utf-8 -*-

import sys
import cv2
import numpy as np
from time import clock

tracked_contours = []

class Contour():
    def __init__(self, contour):
        self.data = get_contour_data(contour)
        self.pixel_error = 5
        self.score = 0

    def __eq__(self, other):
        for i in range(len(self.data)):
            if abs(self.data[i]-other.data[i]) > self.pixel_error:
                return False
        return True

def get_contour_data(contour):
    xx = np.array([ a[0][0] for a in contour ])
    yy = np.array([ a[0][1] for a in contour ])
    return [xx.min(), yy.min(), xx.max(), yy.max()]

def check_contours(contours, count, img):
    for tracked_contour in tracked_contours:
        if count % 2 == 0:
            tracked_contour.score -= 1

        if tracked_contour.score < 0:
            tracked_contours.remove(tracked_contour)

    for contour in contours:
        c = Contour(contour)
        if c in tracked_contours:
            i = tracked_contours.index(c)
            tracked_contours[i].score += 1
            cv2.rectangle(img, (tracked_contours[i].data[0], \
                tracked_contours[i].data[1]), (tracked_contours[i].data[2], \
                tracked_contours[i].data[3]), (tracked_contours[i].score*10, tracked_contours[i].score*5, tracked_contours[i].score), tracked_contours[i].score)
            if tracked_contours[i].score > 40:
                return True, c
        else: tracked_contours.append(c)

    return False, None

def drawContours(contours, img):
    for contour in contours:
        data = get_contour_data(contour)
        cv2.rectangle(img, (data[0], data[1]), (data[2], data[3]), (255,0,0))

def detect(file_name):
    c = cv2.VideoCapture(file_name)
    _,f = c.read()
    f = cv2.cvtColor(f, cv2.COLOR_BGR2GRAY)

    avg = np.float32(f)

    cv2.namedWindow("img")
    cv2.namedWindow("grey")
    cv2.namedWindow("avg")

    t = 0
    count = 0

    while(1):
        if t % 5 != 0:
            _,f = c.read()
            if f == None:
                exit(1)
            t+=1
            continue
        count += 1
        t += 1

        _,f = c.read()

        if f == None:
            exit(1)

        cv2.imshow('img',f)

        f = np.float32(cv2.cvtColor(f, cv2.COLOR_BGR2GRAY))

        cv2.accumulateWeighted(f, avg, 0.005)

        res = cv2.convertScaleAbs(avg)

        cv2.imshow('grey',res)

        thresh, res = cv2.threshold(res, 200, 255, cv2.THRESH_BINARY)
        kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(40,40))
        mat = cv2.dilate(res,kernel)

        contours, hierarchy = cv2.findContours(mat,cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_TC89_L1)
        res = cv2.cvtColor(res, cv2.COLOR_GRAY2BGR)
        a,b = check_contours(contours, count, res)

        if a == True:
            cv2.rectangle(res, (b.data[0], b.data[1]), (b.data[2], b.data[3]), (0,255,0), 5)
            cv2.imshow('avg',res)
            k = cv2.waitKey(5000 ...
(more)
2013-02-08 07:22:01 -0600 commented answer Hot to detect logo region in video?

I think about searching region with no difference. But how can I do it (I use python) ? I only need detect logo region, so I need data: X coordinate of the top left corner of the logo region, Y coordinate of the top left corner of the logo region, width of the logo region, height of the logo region.

2013-02-08 07:18:09 -0600 commented answer Hot to detect logo region in video?

Main condition: I don't know before video processing how the logo looks like. So I can't make and use any template. That is the salt of problem.

2013-02-08 00:25:24 -0600 received badge  Student (source)
2013-02-07 23:46:21 -0600 asked a question Hot to detect logo region in video?

Hi,

I have video. I need to detect logo region( x y width height). Region=red rectangle. image description

I do not know in advance how the logo looks like, I do not have its picture.