This file contains hidden or 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
| def valuechange(self): | |
| # We access our global variables within the function | |
| global framesTaken | |
| global framesSpecified | |
| # We set the framesSpecified value to | |
| # whatever is specified on the spinbox | |
| framesSpecified = self.sp.value() | |
| # We modify our label to give us info, how many |
This file contains hidden or 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
| def take_snapshot(self): | |
| # Import the global variables we'll be using | |
| global framesTaken, clusters, borderSize, offset | |
| # This will be needed to check if the player was playing at the | |
| # time of the button press | |
| wasPlaying = None | |
| # We need to get the width and height of the video file | |
| videoSize = self.mediaplayer.video_get_size() | |
| # This is the VLC function, that let's us | |
| # take a snap shot of the video frame and save it in the directory |
This file contains hidden or 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
| # Courtesy of https://www.pyimagesearch.com/2014/05/26/opencv-python-k-means-color-clustering/ | |
| def centroid_histogram(clt): | |
| # grab the number of different clusters and create a histogram | |
| # based on the number of pixels assigned to each cluster | |
| numLabels = np.arange(0, len(np.unique(clt.labels_)) + 1) | |
| (hist, _) = np.histogram(clt.labels_, bins=numLabels) | |
| # normalize the histogram, such that it sums to one | |
| hist = hist.astype("float") | |
| hist /= hist.sum() | |
| # return the histogram |
This file contains hidden or 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
| # Courtesy of https://www.pyimagesearch.com/2014/05/26/opencv-python-k-means-color-clustering/ | |
| def plot_colors(hist, centroids): | |
| # initialize the bar chart representing the relative frequency | |
| # of each of the colors | |
| bar = np.zeros((50, 300, 3), dtype="uint8") | |
| startX = 0 | |
| # Sort the centroids to form a gradient color look | |
| centroids = sorted(centroids, key=lambda x: sum(x)) |
This file contains hidden or 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
| # Let's fetch the video frame we just captured | |
| imagePath = os.getcwd() + "/img_"+str(framesTaken)+".png" | |
| # Transform the image to an OpenCV readable image | |
| image = cv2.imread(imagePath) | |
| # Let's make a copy of this image | |
| # to use for the color palette generation | |
| image_copy = image_resize(cv2.cvtColor( | |
| image, cv2.COLOR_BGR2RGB), width=100) |
This file contains hidden or 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
| # To show a thumbnail version of this image, we need to store it | |
| # in a pixmap and then add it to a label widget | |
| pixmap = QtGui.QPixmap() | |
| pixmap.load(imagePath) | |
| pixmap = pixmap.scaledToWidth(50) | |
| self.imageBoxes[framesTaken].setPixmap(pixmap) | |
| framesTaken = framesTaken + 1 | |
| # Now that we have at least one image captured and processed, | |
| # we can go ahead and show the bottom layout with our thumbnail labels |
This file contains hidden or 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
| # Once the list is full with all the images we need, we can start to | |
| # combine it into the final output image | |
| if (framesTaken == framesSpecified): | |
| resultImgs = [] | |
| for i in framesTakenList: | |
| # here we just add a whitespace rectangle as a top margin | |
| resultImgs.append(cv2.imread(i)) | |
| im = np.zeros(( | |
| borderSize*2, | |
| cv2.imread(i).shape[1], |
This file contains hidden or 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
| #!/usr/bin/env bash | |
| # esp32-ai: clone, train, export, build, and flash — end to end | |
| # Reproduces github.com/slvDev/esp32-ai from a bare board. | |
| # Requires: ESP32-S3 N16R8 (16MB flash, 8MB PSRAM). | |
| # | |
| # Usage: | |
| # ./build_and_flash.sh # full run: data prep, train, export, build, flash | |
| # ./build_and_flash.sh --skip-train # reuse an existing firmware/model/model.bin, just build + flash | |
| set -euo pipefail |
This file contains hidden or 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
| #!/usr/bin/env bash | |
| # esp32-ai: test a custom prompt against an already-trained, already-flashed model. | |
| # Does NOT retrain and does NOT rewrite the 15MB model partition. | |
| # | |
| # Usage: | |
| # ./run_custom_prompt.sh "Once there was a robot" | |
| set -euo pipefail | |
| if [ "$#" -lt 1 ]; then | |
| echo "Usage: $0 \"Your custom prompt\"" |
OlderNewer