Skip to content

Commit

Permalink
Began combining code from CV input
Browse files Browse the repository at this point in the history
  • Loading branch information
ishani-das authored Dec 2, 2021
1 parent 7ff6f6d commit 08ad3e7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 10 deletions.
58 changes: 48 additions & 10 deletions frc_ball_detection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,25 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 14,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "ImportError",
"evalue": "cannot import name 'VideoFileGenerator' from 'VideoFileGeneratorFile' (/Users/ishanidas/Desktop/FRC/VideoFileGeneratorFile.py)",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mImportError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-14-ecc1115072ea>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mcv2\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mnumpy\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0mVideoFileGeneratorFile\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mVideoFileGenerator\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mImportError\u001b[0m: cannot import name 'VideoFileGenerator' from 'VideoFileGeneratorFile' (/Users/ishanidas/Desktop/FRC/VideoFileGeneratorFile.py)"
]
}
],
"source": [
"import cv2\n",
"import numpy as np"
"import numpy as np\n",
"from VideoFileGeneratorFile import VideoFileGenerator"
]
},
{
Expand All @@ -19,7 +32,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -79,26 +92,29 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"class ColorDetector:\n",
" \n",
" def __init__(self, image_name, lower_bound, upper_bound):\n",
" self.image = cv2.imread(image_name)\n",
" def __init__(self, video_name, lower_bound, upper_bound):\n",
" # self.image = cv2.imread(image_name)\n",
" self.video = VideoFileGeneratorFile.VideoFileGenerator(video_name)\n",
" self.lower_bound = np.array(lower_bound)\n",
" self.upper_bound = np.array(upper_bound)\n",
" \n",
" def detect(self):\n",
" \n",
" image = self.video.get_next_frame()\n",
"\n",
" # Convert BGR to HSV\n",
" hsv = cv2.cvtColor(self.image, cv2.COLOR_BGR2HSV)\n",
" hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)\n",
" \n",
" mask = cv2.inRange(hsv, self.lower_bound, self.upper_bound)\n",
" output = cv2.bitwise_and(self.image,self.image, mask= mask)\n",
" output = cv2.bitwise_and(image,image, mask= mask)\n",
" \n",
" cv2.imshow(\"Color Detected\", np.hstack((self.image,output)))\n",
" cv2.imshow(\"Color Detected\", np.hstack((image,output)))\n",
" cv2.waitKey(0)\n",
" cv2.destroyAllWindows()"
]
Expand Down Expand Up @@ -130,6 +146,28 @@
"flower_detector.detect()"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "module 'VideoFileGeneratorFile' has no attribute 'VideoFileGenerator'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-13-ff488b88d097>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mball_vid_detector\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mColorDetector\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"test_vid.mov\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;36m26\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m50\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m50\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;36m30\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m255\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m255\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m<ipython-input-12-69649a3f98a9>\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, video_name, lower_bound, upper_bound)\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__init__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvideo_name\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlower_bound\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mupper_bound\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;31m# self.image = cv2.imread(image_name)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvideo\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mVideoFileGeneratorFile\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mVideoFileGenerator\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvideo_name\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 6\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlower_bound\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0marray\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlower_bound\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mupper_bound\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0marray\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mupper_bound\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mAttributeError\u001b[0m: module 'VideoFileGeneratorFile' has no attribute 'VideoFileGenerator'"
]
}
],
"source": [
"ball_vid_detector = ColorDetector(\"test_vid.mov\", [26,50,50], [30,255,255])"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
Binary file added test_vid.mov
Binary file not shown.

0 comments on commit 08ad3e7

Please sign in to comment.