finalization of pointbase functionality, removed old scripts, removed camera scripts, they will be added into their own folder
parent
3025a56f36
commit
3995ba6298
After Width: | Height: | Size: 2.0 MiB |
After Width: | Height: | Size: 1.2 MiB |
@ -1,60 +0,0 @@
|
||||
import cv2
|
||||
import numpy as np
|
||||
import os
|
||||
|
||||
|
||||
def variance_of_laplacian(image):
|
||||
return cv2.Laplacian(image, cv2.CV_64F).var()
|
||||
|
||||
|
||||
|
||||
os.environ["OPENCV_FFMPEG_CAPTURE_OPTIONS"]="rtsp_transport;tcp"
|
||||
|
||||
gstreamerstr = "tcpclientsrc host=192.168.0.144 port=5000 ! jpegdec ! videoconvert ! appsink"
|
||||
|
||||
|
||||
|
||||
#if not capture.isOpened() : print("CANNOT OPEN STREAM")
|
||||
capture = cv2.VideoCapture("vid.mp4")
|
||||
keypressNo = 1
|
||||
while(True):
|
||||
#capture = cv2.VideoCapture(gstreamerstr,cv2.CAP_GSTREAMER)
|
||||
|
||||
ret, frame = capture.read()
|
||||
if not ret:
|
||||
print('fail')
|
||||
break
|
||||
|
||||
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
||||
variance = variance_of_laplacian(frame)
|
||||
|
||||
cv2.putText(frame, "{}: {:.2f}".format("Variance:", variance), (10, 30),
|
||||
cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 3)
|
||||
cv2.imshow('frame',frame)
|
||||
#cv2.waitKey(0)
|
||||
|
||||
if cv2.waitKey(70) == ord('v'):
|
||||
frames=[]
|
||||
maxVarIdx = 0
|
||||
maxVar = 0
|
||||
for i in range(5):
|
||||
ret, frame = capture.read()
|
||||
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
||||
frames.append(frame)
|
||||
var = variance_of_laplacian(frame)
|
||||
if var > maxVar:
|
||||
maxVar = var
|
||||
maxVarIdx = i
|
||||
cv2.waitKey(20)
|
||||
#test to see if the image with the highest variance gets picked
|
||||
#cv2.putText(frame, "{}: {:.2f}".format("Variance:", var), (10, 30),
|
||||
#cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 3)
|
||||
#writeString="imgtest"+str(keypressNo)+str(i)+".jpg"
|
||||
#cv2.imwrite(writeString, frames[i])
|
||||
writeString="img"+str(keypressNo)+".jpg"
|
||||
cv2.imwrite(writeString, frames[maxVarIdx])
|
||||
keypressNo=keypressNo+1
|
||||
|
||||
|
||||
capture.release()
|
||||
cv2.destroyAllWindows()
|
@ -1,38 +0,0 @@
|
||||
import cv2
|
||||
import numpy as np
|
||||
import os
|
||||
from imutils import paths
|
||||
import argparse
|
||||
|
||||
|
||||
def variance_of_laplacian(image):
|
||||
return cv2.Laplacian(image, cv2.CV_64F).var()
|
||||
|
||||
|
||||
def minVarInFolder(path):
|
||||
minVar = 90000
|
||||
minPath=""
|
||||
files = os.listdir(path)
|
||||
for p in files:
|
||||
if ".png" in p and ".mask" not in p:
|
||||
print(path+p)
|
||||
img = cv2.imread(path+p)
|
||||
cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
||||
var = variance_of_laplacian(img)
|
||||
if var < minVar:
|
||||
minPath = path+p
|
||||
minVar = var
|
||||
return minPath,minVar
|
||||
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("-i", "--images", required=True,
|
||||
help="path to image")
|
||||
args = vars(ap.parse_args())
|
||||
|
||||
path = args["images"]
|
||||
|
||||
#img = cv2.imread(path)
|
||||
#cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
||||
#var = variance_of_laplacian(img)
|
||||
|
||||
print(minVarInFolder(path))
|
File diff suppressed because it is too large
Load Diff
@ -1 +0,0 @@
|
||||
gst-launch-1.0 -v v4l2src device=/dev/video0 num-buffers=-1 ! video/x-raw,width=640,height=480, framerate=30/1 ! videoconvert ! jpegenc ! tcpserversink host=192.168.0.144 port=5000
|
@ -1,71 +0,0 @@
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/core.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include <iostream>
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
// static void help()
|
||||
// {
|
||||
// cout << "\nThis program demonstrates kmeans clustering.\n"
|
||||
// "It generates an image with random points, then assigns a random number of cluster\n"
|
||||
// "centers and uses kmeans to move those cluster centers to their representitive location\n"
|
||||
// "Call\n"
|
||||
// "./kmeans\n" << endl;
|
||||
// }
|
||||
int main( int /*argc*/, char** /*argv*/ )
|
||||
{
|
||||
const int MAX_CLUSTERS = 5;
|
||||
Scalar colorTab[] =
|
||||
{
|
||||
Scalar(0, 0, 255),
|
||||
Scalar(0,255,0),
|
||||
Scalar(255,100,100),
|
||||
Scalar(255,0,255),
|
||||
Scalar(0,255,255)
|
||||
};
|
||||
Mat img(500, 500, CV_8UC3);
|
||||
RNG rng(12345);
|
||||
for(;;)
|
||||
{
|
||||
int k, clusterCount = rng.uniform(2, MAX_CLUSTERS+1);
|
||||
int i, sampleCount = rng.uniform(1, 1001);
|
||||
Mat points(sampleCount, 1, CV_32FC2), labels;
|
||||
clusterCount = MIN(clusterCount, sampleCount);
|
||||
std::vector<Point2f> centers;
|
||||
/* generate random sample from multigaussian distribution */
|
||||
for( k = 0; k < clusterCount; k++ )
|
||||
{
|
||||
Point center;
|
||||
center.x = rng.uniform(0, img.cols);
|
||||
center.y = rng.uniform(0, img.rows);
|
||||
Mat pointChunk = points.rowRange(k*sampleCount/clusterCount,
|
||||
k == clusterCount - 1 ? sampleCount :
|
||||
(k+1)*sampleCount/clusterCount);
|
||||
rng.fill(pointChunk, RNG::NORMAL, Scalar(center.x, center.y), Scalar(img.cols*0.05, img.rows*0.05));
|
||||
}
|
||||
randShuffle(points, 1, &rng);
|
||||
double compactness = kmeans(points, clusterCount, labels,
|
||||
TermCriteria( TermCriteria::EPS+TermCriteria::COUNT, 10, 1.0),
|
||||
3, KMEANS_PP_CENTERS, centers);
|
||||
img = Scalar::all(0);
|
||||
for( i = 0; i < sampleCount; i++ )
|
||||
{
|
||||
int clusterIdx = labels.at<int>(i);
|
||||
Point ipt = points.at<Point2f>(i);
|
||||
circle( img, ipt, 2, colorTab[clusterIdx], FILLED, LINE_AA );
|
||||
}
|
||||
for (i = 0; i < (int)centers.size(); ++i)
|
||||
{
|
||||
Point2f c = centers[i];
|
||||
circle( img, c, 40, colorTab[i], 1, LINE_AA );
|
||||
}
|
||||
cout << "Compactness: " << compactness << endl;
|
||||
cout << "Labels rows" << labels.rows;
|
||||
cout << "Labels cols" << labels.cols;
|
||||
imshow("clusters", img);
|
||||
char key = (char)waitKey();
|
||||
if( key == 27 || key == 'q' || key == 'Q' ) // 'ESC'
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
// CPP program to Stitch
|
||||
// input images (panorama) using OpenCV
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
// Include header files from OpenCV directory
|
||||
// required to stitch images.
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/stitching.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
// Define mode for stitching as panorama
|
||||
// (One out of many functions of Stitcher)
|
||||
Stitcher::Mode mode = Stitcher::SCANS;
|
||||
|
||||
// Array for pictures
|
||||
vector<Mat> imgs;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
// Get all the images that need to be
|
||||
// stitched as arguments from command line
|
||||
for (int i = 1; i < argc; ++i)
|
||||
{
|
||||
// Read the ith argument or image
|
||||
// and push into the image array
|
||||
Mat img = imread(argv[i]);
|
||||
if (img.empty())
|
||||
{
|
||||
// Exit if image is not present
|
||||
cout << "Can't read image '" << argv[i] << "'\n";
|
||||
return -1;
|
||||
}
|
||||
imgs.push_back(img);
|
||||
}
|
||||
|
||||
// Define object to store the stitched image
|
||||
Mat pano;
|
||||
|
||||
// Create a Stitcher class object with mode panoroma
|
||||
Ptr<Stitcher> stitcher = Stitcher::create(mode);
|
||||
|
||||
// Command to stitch all the images present in the image array
|
||||
Stitcher::Status status = stitcher->stitch(imgs, pano);
|
||||
|
||||
if (status != Stitcher::OK)
|
||||
{
|
||||
// Check if images could not be stitched
|
||||
// status is OK if images are stitched successfully
|
||||
cout << "Can't stitch images\n";
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Store a new image stitched from the given
|
||||
//set of images as "result.jpg"
|
||||
imwrite("result.jpg", pano);
|
||||
|
||||
// Show the result
|
||||
imshow("Result", pano);
|
||||
|
||||
waitKey(0);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in new issue