2017-07-24 01:32:48 -0600
| asked a question | is there any specific function to find width and height of any object in python and opencv ? how to find width and height of any object using python and opencv |
2017-07-20 02:02:25 -0600
| asked a question | how to get height of any object using python and opencv import cv2
import numpy as np img = cv2.imread("C:\Users\User\Desktop\cc.png", cv2.IMREAD_GRAYSCALE) read picture imgray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) BGR to grayscale ret, thresh = cv2.threshold(img, 200, 255, cv2.THRESH_BINARY_INV)
image, contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(img, contours, -1, (0, 255, 0), 3) cv2.imwrite("contour.jpg", img)
cv2.imshow("g",img)
cv2.waitKey(0) cv2.destroyAllWindows() |
2017-07-20 02:00:12 -0600
| received badge | ● Enthusiast
|
2017-07-18 00:32:26 -0600
| asked a question | hello anyone answer me how to pass command line arguments through python and how this error occurs usage: object_size.py [-h] -i IMAGE -w WIDTH object_size.py: error: argument -i/--image is required in this below code from scipy.spatial import distance as dist
from imutils import perspective
from imutils import contours
import numpy as np
import argparse
import imutils
import cv2
...
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True,
help="path to the input image")
ap.add_argument("-w", "--width", type=float, required=True,
help="width of the left-most object in the image (in inches)")
args = vars(ap.parse_args())
image = cv2.imread(args["image"])
...
|
2017-07-07 02:13:35 -0600
| asked a question | hello guys am pretty new to this opencv so can anyone help me how contourArea(); function works in opencv in detail and how does it returns in double and here is the piece of code #include <iostream>
include "opencv2/core/core.hpp" include "opencv2/imgproc/imgproc.hpp" include "opencv2/highgui/highgui.hpp" include"math.h" include <sstream> int main(int argc, const char * argv[]) { cv::Mat image = cv::imread("C:\\Users\\User\\Desktop\\untitled.png");
//cv::Mat image=cv::imread("C:\Users\User\Desktop"
if (!image.data) {
std::cout << "Image file not found\n";
return 1;
}
//Prepare the image for findContours
cv::cvtColor(image, image, CV_BGR2GRAY);
cv::threshold(image, image, 150, 255, CV_THRESH_BINARY);
//Find the contours. Use the contourOutput Mat so the original image doesn't get overwritten
std::vector<std::vector<cv::Point> > contours;
cv::Mat contourOutput = image.clone();
cv::findContours(contourOutput, contours, CV_RETR_TREE, CV_CHAIN_APPROX_NONE);
//Draw the contours
cv::Mat contourImage(image.size(), CV_8UC3, cv::Scalar(0, 0, 0));
cv::Scalar colors[3];
colors[0] = cv::Scalar(255, 0, 0);
colors[1] = cv::Scalar(0, 255, 0);
colors[2] = cv::Scalar(0, 0, 255);
for (size_t idx = 0; idx < contours.size(); idx++) {
int thickness =2 ;
//size_t idx = 2;
cv::drawContours(contourImage,contours,idx,colors[idx % 1],thickness);
//cv::drawContours(contourImage, contours, idx, colors[idx % 1], thickness);
}
for (int i = 0; i < contours.size(); i++)
std::cout << "Area " << i << ": " << contourArea(contours[i]) << std::endl;
cv::imshow("thresholded Image", image);
cvMoveWindow("Input Image", 0, 0);
cv::imshow("Contours", contourImage);
cvMoveWindow("Contours", 200, 0);
cv::waitKey(0);
return 0;
} |
2017-07-07 01:31:32 -0600
| commented question | can anyone reply how does this contourArea() function works ?is there any formula behind it to get values in double i just want to know how contourArea() function works in detail |
2017-07-07 00:11:59 -0600
| asked a question | can anyone reply how does this contourArea() function works ?is there any formula behind it to get values in double #include <iostream> include "opencv2/core/core.hpp" include "opencv2/imgproc/imgproc.hpp" include "opencv2/highgui/highgui.hpp" include"math.h" include <sstream> int main(int argc, const char * argv[]) { cv::Mat image = cv::imread("C:\\Users\\User\\Desktop\\untitled.png");
//cv::Mat image=cv::imread("C:\Users\User\Desktop"
if (!image.data) {
std::cout << "Image file not found\n";
return 1;
}
//Prepare the image for findContours
cv::cvtColor(image, image, CV_BGR2GRAY);
cv::threshold(image, image, 150, 255, CV_THRESH_BINARY);
//Find the contours. Use the contourOutput Mat so the original image doesn't get overwritten
std::vector<std::vector<cv::Point> > contours;
cv::Mat contourOutput = image.clone();
cv::findContours(contourOutput, contours, CV_RETR_TREE, CV_CHAIN_APPROX_NONE);
//Draw the contours
cv::Mat contourImage(image.size(), CV_8UC3, cv::Scalar(0, 0, 0));
cv::Scalar colors[3];
colors[0] = cv::Scalar(255, 0, 0);
colors[1] = cv::Scalar(0, 255, 0);
colors[2] = cv::Scalar(0, 0, 255);
for (size_t idx = 0; idx < contours.size(); idx++) {
int thickness =2 ;
//size_t idx = 2;
cv::drawContours(contourImage,contours,idx,colors[idx % 1],thickness);
//cv::drawContours(contourImage, contours, idx, colors[idx % 1], thickness);
}
for (int i = 0; i < contours.size(); i++)
std::cout << "Area " << i << ": " << contourArea(contours[i]) << std::endl;
|
2017-07-06 08:49:33 -0600
| commented answer | Problem with contourArea return value can anyone reply how does this contourArea() function works ?is there any formula behind it to get values in double |