Nombre: Byron Alejandro Carrera Sánchez NRC: 9503 Carrera: Ingeniería Mecatrónica
This document describes creating a GUI using trackbars in OpenCV to apply different thresholding techniques to video frames from a webcam including binary, inverted binary, truncated, to zero, inverted to zero, Otsu, adaptive mean, and adaptive Gaussian thresholding. Threshold, block size, and constant values can be modified using the trackbars.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
30 views7 pages
Nombre: Byron Alejandro Carrera Sánchez NRC: 9503 Carrera: Ingeniería Mecatrónica
This document describes creating a GUI using trackbars in OpenCV to apply different thresholding techniques to video frames from a webcam including binary, inverted binary, truncated, to zero, inverted to zero, Otsu, adaptive mean, and adaptive Gaussian thresholding. Threshold, block size, and constant values can be modified using the trackbars.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7
´
OPRATIVA DE PROFESIONALIZACIÓN
Nombre: Byron Alejandro Carrera Sánchez
NRC: 9503 Carrera: Ingeniería Mecatrónica Se uso trackbars para crear una GUI que permita pasar de threshold binario, binario invertido, truncado, a zero, a zero invertido, otsu, adaptativo promedio, adaptativo gauss.
• Otro trackbar para modificar el umbral.
• Otro trackbar para modificar block size • Otro trackbar para modificar c from __future__ import print_function import cv2 import argparse cap = cv2.VideoCapture(0) def tipo_threshold(val): pass cv2.namedWindow('IMAGEN') cv2.createTrackbar('Threshold','IMAGEN',0,8,tipo_threshold) cv2.createTrackbar('UMBRAL','IMAGEN',0,255,tipo_threshold) cv2.createTrackbar('BLOCK_SIZE','IMAGEN',5,29,tipo_threshold) cv2.createTrackbar('C','IMAGEN',1,10,tipo_threshold) while(True): # Capture frame-by-frame th = cv2.getTrackbarPos('Threshold', 'IMAGEN') umb = cv2.getTrackbarPos('UMBRAL', 'IMAGEN') bz = cv2.getTrackbarPos('BLOCK_SIZE', 'IMAGEN') c = cv2.getTrackbarPos('C', 'IMAGEN') if bz%2==0: bz=bz+1 else: bz=bz ret, frame = cap.read() g = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) #g = cv2.multiply(g,0.25) #b, g, r, = cv2.split(frame) # Threshold _, umbral = cv2.threshold(g, umb, 255, cv2.THRESH_BINARY) _, umbral1 = cv2.threshold(g, umb, 255, cv2.THRESH_BINARY_INV) _, umbral2 = cv2.threshold(g, umb, 255, cv2.THRESH_TRUNC) _, umbral3 = cv2.threshold(g, umb, 255, cv2.THRESH_TOZERO) _, umbral4 = cv2.threshold(g, umb, 255, cv2.THRESH_TOZERO_INV) _, umbral5 = cv2.threshold(g, umb, 255, cv2.THRESH_OTSU) umbral6 = cv2.adaptiveThreshold(g, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY,bz,c) umbral7 = cv2.adaptiveThreshold(g, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY,bz,c) if th==0: cv2.imshow('IMAGEN',frame) if th == 1: cv2.imshow('IMAGEN', umbral) if th == 2: cv2.imshow('IMAGEN', umbral1) if th == 3: cv2.imshow('IMAGEN', umbral2) if th == 4: cv2.imshow('IMAGEN', umbral3) if th == 5: cv2.imshow('IMAGEN', umbral4) if th == 6: cv2.imshow('IMAGEN', umbral5) if th == 7: cv2.imshow('IMAGEN', umbral6) if th == 8: cv2.imshow('IMAGEN', umbral7)