-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
042a428
commit 3c97964
Showing
1 changed file
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |