From 3c979649695991179cba3c996f1df80c0bc078ec Mon Sep 17 00:00:00 2001 From: risyadrzky <75091346+risyadrzky@users.noreply.github.com> Date: Tue, 26 Jan 2021 12:09:43 +0700 Subject: [PATCH] Add files via upload --- Mineral Selector.ipynb | 126 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 Mineral Selector.ipynb diff --git a/Mineral Selector.ipynb b/Mineral Selector.ipynb new file mode 100644 index 0000000..9075a7d --- /dev/null +++ b/Mineral Selector.ipynb @@ -0,0 +1,126 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# MINERAL SELECTOR" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import cv2 as cv2\n", + "import numpy as np" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(hMin = -1 , sMin = -1, vMin = -1), (hMax = -1 , sMax = -1, vMax = -1)\n" + ] + } + ], + "source": [ + "def nothing(x):\n", + " pass\n", + "\n", + "# Insert your Core Sample Image\n", + "CSample = cv2.imread('Insert Your Core Image Location Here')\n", + "\n", + "# Create a window\n", + "cv2.namedWindow('Mineral Selector')\n", + "\n", + "# Create trackbars for color change\n", + "# Hue is from 0-179 for Opencv\n", + "cv2.createTrackbar('HMin', 'image', 0, 179, nothing)\n", + "cv2.createTrackbar('SMin', 'image', 0, 255, nothing)\n", + "cv2.createTrackbar('VMin', 'image', 0, 255, nothing)\n", + "cv2.createTrackbar('HMax', 'image', 0, 179, nothing)\n", + "cv2.createTrackbar('SMax', 'image', 0, 255, nothing)\n", + "cv2.createTrackbar('VMax', 'image', 0, 255, nothing)\n", + "\n", + "# Set default value for Max HSV trackbars\n", + "cv2.setTrackbarPos('HMax', 'image', 179)\n", + "cv2.setTrackbarPos('SMax', 'image', 255)\n", + "cv2.setTrackbarPos('VMax', 'image', 255)\n", + "\n", + "# Initialize HSV min/max values\n", + "hMin = sMin = vMin = hMax = sMax = vMax = 0\n", + "phMin = psMin = pvMin = phMax = psMax = pvMax = 0\n", + "\n", + "while(1):\n", + " # Get current positions of all trackbars\n", + " hMin = cv2.getTrackbarPos('HMin', 'image')\n", + " sMin = cv2.getTrackbarPos('SMin', 'image')\n", + " vMin = cv2.getTrackbarPos('VMin', 'image')\n", + " hMax = cv2.getTrackbarPos('HMax', 'image')\n", + " sMax = cv2.getTrackbarPos('SMax', 'image')\n", + " vMax = cv2.getTrackbarPos('VMax', 'image')\n", + "\n", + " # Set minimum and maximum HSV values to display\n", + " lower = np.array([hMin, sMin, vMin])\n", + " upper = np.array([hMax, sMax, vMax])\n", + "\n", + " # Convert to HSV format and color threshold\n", + " hsv = cv2.cvtColor(CSample, cv2.COLOR_BGR2HSV)\n", + " mask = cv2.inRange(hsv, lower, upper)\n", + " result = cv2.bitwise_and(CSample, CSample, mask=mask)\n", + "\n", + " # Print if there is a change in HSV value\n", + " if((phMin != hMin) | (psMin != sMin) | (pvMin != vMin) | (phMax != hMax) | (psMax != sMax) | (pvMax != vMax) ):\n", + " print(\"(hMin = %d , sMin = %d, vMin = %d), (hMax = %d , sMax = %d, vMax = %d)\" % (hMin , sMin , vMin, hMax, sMax , vMax))\n", + " phMin = hMin\n", + " psMin = sMin\n", + " pvMin = vMin\n", + " phMax = hMax\n", + " psMax = sMax\n", + " pvMax = vMax\n", + "\n", + " # Display mineral result\n", + " cv2.imshow('Selected Mineral', result)\n", + " if cv2.waitKey(10) & 0xFF == ord('q'):\n", + " break\n", + "\n", + "cv2.destroyAllWindows()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.3" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}