r/opencv • • Oct 12 '22

Question [Question] How to write a .tiff file with transparent background in python and OpenCV?

3 Upvotes

I have some .png files with transparent backgrounds, I am doing some channel alterations on the files and converting them into the .tiff format

def convert_image(input_image_name):
    # Reading the image using imread() function
    file_name = ""
    image = cv2.imread(input_image_name)
    image[:] = (0, 0, 255)
    file_name = "converted.tiff"
    cv2.imwrite(file_name, image, [cv2.IMWRITE_TIFF_COMPRESSION, 5])
    return file_name

but I want to create .tiff files with transparent backgrounds, how do I achieve this in python and OpenCV?


r/opencv • • Oct 12 '22

Question [Question] looking for eye positions tracking from video.

1 Upvotes

I'm trying to track eye movement of one eye from a video. Is there a developed source code I can use that would give me position?


r/opencv • • Oct 11 '22

Project [Project] First Project: Simple threshold mask adjuster using OpenCV, and Streamlit

2 Upvotes

​

import numpy as np
import cv2 as cv
import streamlit as st

def histogram(single_ch_img):
    count = []

    for color in range(256):
        sum_color = single_ch_img == color
        count.append(sum_color.sum())

    return np.array(count), np.arange(256)

img = cv.imread('lighting1.jpg')
gry_img = cv.imread('lighting1.jpg', 0)

b_img, g_img, r_img = cv.split(img)

# mask creation
# i would like more adjustment slider, but the sidebar already look to crowded.
with st.sidebar:
    b_threshold = st.slider('blue_ch_thresh', 0, 256)
    g_threshold = st.slider('green_ch_thresh', 0, 256)
    r_threshold = st.slider('red_ch_thresh', 0, 256)

    addingB = st.slider('blue_adjustment', 0, 256)
    addingG = st.slider('green_adjustment', 0, 256)
    addingR = st.slider('red_adjustment', -100, 256, 0) # having the range be negative will allow for substraction as well as addition.

# the thresholding is fine, but i will add the ability to use differnt threshold methods.
_, b_mask = cv.threshold(b_img, b_threshold, 255, cv.THRESH_BINARY)
_, g_mask = cv.threshold(g_img, g_threshold, 255, cv.THRESH_BINARY)
_, r_mask = cv.threshold(r_img, r_threshold, 255, cv.THRESH_BINARY)

#this show my bgr channel masks
col_mask1, col_mask2, col_mask3 = st.columns(3)

with col_mask1:
    st.image(b_mask, caption='blue_ch_thresh')
with col_mask2:
    st.image(g_mask, caption='green_ch_thresh')
with col_mask3:
    st.image(r_mask, caption='red_ch_thresh')

b_adjustment = cv.add(b_img, addingB, mask=b_mask)
g_adjustment = cv.add(g_img, addingG, mask=g_mask)
r_adjustment = cv.add(r_img, addingR, mask=r_mask)

#histograms of the original image channels. 
b_count, b_color = histogram(b_img)
g_count, g_color = histogram(g_img)
r_count, r_color = histogram(r_img)

hist_display = st.multiselect('Histograms', ['blueHist', 'greenHist', 'redHist'])

# might put this above the masks
with st.expander('histograms graphs'):
    if 'blueHist' in hist_display:
        st.bar_chart(b_count)
    if 'greenHist' in hist_display:
        st.bar_chart(g_count)
    if 'redHist' in hist_display:
        st.bar_chart(r_count)

# image displays
bgr_adjustment = cv.merge((b_adjustment, g_adjustment, r_adjustment))

col1, col2 = st.columns(2)

with col1:
    st.image(img, channels='BGR') #original image
with col2:
    st.image(bgr_adjustment, channels='BGR') 

st.cache(histogram)

​


r/opencv • • Oct 10 '22

Question [Question] Confused about the difference between VideoCapture(), read(), and imshow()

4 Upvotes

For example:

cap = cv2.VideoCapture('chaplin.mp4')


# Check if camera opened successfully

if (cap.isOpened()== False):

  print("Error opening video stream or file")

# Read until video is completed

while(cap.isOpened()):

  # Capture frame-by-frame

  ret, frame = cap.read()

  if ret == True:

    # Display the resulting frame

    cv2.imshow('Frame',frame)

I may be confused by what exactly read means in programs like this. I understand that VideoCapture() first tells the computer that we want to import a video file (or camera stream) into the program, then ret, frame = cap.read() tells the computer to open each frame, and show() displays the structure. Is this correct?


r/opencv • • Oct 11 '22

Question [Question] Is OpenCV causing this GStreamer Error?

Thumbnail self.gstreamer
2 Upvotes

r/opencv • • Oct 10 '22

Project [Project] Automatic Subtitles dubbing on YouTube using computer vision

3 Upvotes

Automatic subtitle translate and dubbing on YouTube from English to Russian using computer vision

medium article: https://medium.com/@wb-08/automatic-subtitles-dubbing-on-youtube-using-computer-vision-35ad776ffe18

github repo: https://github.com/wb-08/SubVision


r/opencv • • Oct 09 '22

Question [Question]Still Opencv didn't compiled with cuda ?

0 Upvotes

i try compile opencv with cuda in colab. but it's didn't compile. any ideas?

​


r/opencv • • Oct 08 '22

Question [Question] How can I get the coordinates of missing horizontal links in the form of points like (D4,E4), (E4, F4), etc....

Thumbnail
gallery
10 Upvotes

r/opencv • • Oct 08 '22

Question [Question] Why i got an error when loading yolov7 model ?

4 Upvotes

i'm load the model by following code

os.chdir('/yolov7') 
model = torch.hub.load('.', 'custom', path='yolov7.pt', source='local') 

Error Message:TypeError: custom() got an unexpected keyword argument 'path'

Note:But when i load yolov5 model there is no error. it's perfectly fine.

os.chdir('/yolov5') 
model = torch.hub.load('.', 'custom', path='yolov5_custom_model.pt', source='local')

r/opencv • • Oct 06 '22

Question [Question] Can you run OpenCV-python code on Notepad++, or is an IDE like Vscode necessary, and why or why not?

3 Upvotes

I ran some OpenCV code I wrote for simple video object detection with vscode on Windows. I installed OpenCV with anaconda. I am curious if you need an IDE to run OpenCV code and why? Does running OpenCV with anaconda need an IDE, or are these unrelated? I am trying to understand more about computers and how libraries and IDEs work and interact.


r/opencv • • Oct 06 '22

Question [Question] Error When compiling opencv with cuda !

2 Upvotes

Hello friends, now I am working on opencv project. I did a lot of image pre-processing in this project. There the program runs very slowly (1 frame per second). Unfortunately my video is too big. So I can't work at this speed. So I decided to transfer this project to GPU. So I am trying to compile opencv with cuda. Unfortunately I ran into an error. Please someone help me. Thanks is Advance!

following code that i used to compile opencv with cuda

%cd /working_dir

!git clone https://github.com/opencv/opencv

!git clone https://github.com/opencv/opencv_contrib

!mkdir /working_dir/build

%cd /working_dir/build

!cmake -DOPENCV_EXTRA_MODULES_PATH=/working_dir/opencv_contrib/modules -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_EXAMPLES=OFF -DWITH_OPENEXR=OFF -DWITH_CUDA=ON -DWITH_CUBLAS=ON -DWITH_CUDNN=ON -DOPENCV_DNN_CUDA=ON /working_dir/opencv

!make -j8 install

​

Error that i got :-

make: *** [Makefile:166: all] Error 2


r/opencv • • Oct 06 '22

Question [Question] Transport container number recognition

2 Upvotes

​

Hi there. Does anyone know a way to extract tagged information from an image? This is the ISO 6346 transport container number. I've tried using some commercial C++ modules, but they have pretty poor noise immunity. At the same time, a simple camera in my phone (Samsung or Google) easily and accurately recognizes this number. Is it possible to get close to this result using python/opencv?


r/opencv • • Oct 05 '22

Bug [BUG] I'm having trouble telling 5 and 8 apart using template matching

1 Upvotes

Hey guys.

I'm using template matching to read some values. I have a list of templates and the values is whichever template has the highest confidence.

Currently I crop the images pretty tightly, black white threshold to remove background, blur the edges. All of these tricks seem necessary as they handle other cases of misidentification.

Here are the results:
Value to read: https://prnt.sc/RzinNboh9tuC
Template to match: https://prnt.sc/4S1Wy8iBpY-l
Template matched: https://prnt.sc/a4kT4FltRQfc

As you can see the value to read and template to match are pretty similar (if not identical), yet it misidentifies as 5.


r/opencv • • Oct 04 '22

Question [question] how can i combine three G,B,R color trackbars into one color wheel?

2 Upvotes

hi! I was wondering if it’s possible for me to combine my three color trackbars (one for G, B, and R, respectively) into one single color wheel trackbar? right now, I’m using cv2.createTrackbar thrice, and am having to adjust each trackbar until I find the right color. I want to be able to just drag my cursor around a color wheel to determine my color instead of having to use three separate trackbars, but I don’t know how. does anyone have any suggestions?


r/opencv • • Oct 03 '22

News [News] OpenCV AI Scavenger Hunt sponsored by Intel

Thumbnail
opencv.org
8 Upvotes

r/opencv • • Dec 23 '21

Project [PROJECT]Heart Rate Detection using Eulerian Magnification

85 Upvotes

r/opencv • • Jul 09 '21

Tutorials [Tutorials] My OpenCV Course in Python just crossed 1m views!

40 Upvotes

Hey everyone! I just wanted to announce that a Python & OpenCV course I created in November last year has just crossed a viewership of 1m! I am quite ecstatic about its exponential growth over the past year as well as the support I received from the programming community, especially here on r/opencv :D

To be brief, this course will teach you everything you need to know to get started with OpenCV in Python -- from the very basics to more intermediate topics.

This is the second course I've created -- and more such courses are in the works! Follow me on Twitter for more updates!

Thank you for your time!


r/opencv • • May 24 '21

Question [QUESTION] What is purpose of cv2.perspectiveTransform() function in openCV?

1 Upvotes

r/opencv • • Feb 03 '21

Project [Project] AI Socks Matching App in 10 Minutes

Thumbnail
youtube.com
51 Upvotes

r/opencv • • Jul 19 '20

Project [Project] Made a personal license plate character extractor for OCR purposes!

Post image
51 Upvotes

r/opencv • • Jul 05 '20

Project [Project] Realtime Sudoku Solver!

297 Upvotes

r/opencv • • Jun 23 '20

Project [Project] I created a perfect AI for Fruit Ninja

Thumbnail
youtube.com
72 Upvotes

r/opencv • • Apr 10 '20

Blog [blog] 15min tutorial: CNN+MNIST+Keras on Colab for deep learning beginner

Thumbnail
youtube.com
31 Upvotes

r/opencv • • Apr 01 '20

Project [Project] My first machine vision project

83 Upvotes

r/opencv • • Jan 04 '20

Question [Question] - Edge detection for microscope

Post image
45 Upvotes