我要做的是测试像素是否为蓝色.
例如:蓝色在RGB中定义为rgb(0,0,255).典型的颜色深度为8位(256色),16位(约65,000),24位(约1600万)和32位(超过40亿种不同颜色).因此,显然有超过1种蓝色.
如果蓝色与否,如何定义蓝色范围并测试每个像素?关于不同的深度,我需要记住什么?
到目前为止我的代码是:
BufferedImage image = ImageIO.read(file);
// Getting pixel color by position x and y
for (int i = 0; i < image.getWidth(); i++) {
for (int j = 0; j < image.getHeight(); j++) {
int clr = image.getRGB(i, j);
Run Code Online (Sandbox Code Playgroud)
注1:
http://www.workwithcolor.com/cyan-blue-color-hue-range-01.htm
这里的问题是,颜色步骤之间是什么?
一个例子就是很棒.
注2:
我刚刚发现了一个关于我感兴趣的话题的演讲:
在第13页,我们可以看到红色的定义.但是你如何定义其他颜色?
所以我的问题更为笼统.我有以下简单的代码:
for(int i=0;i<10;i++){
long starttime=System.nanoTime();
System.out.println("test");
long runtime=System.nanoTime()-starttime;
System.out.println(i + ":" +"runtime="+runtime);
}
Run Code Online (Sandbox Code Playgroud)
我收到以下输出:
test
0:runtime=153956
test
1:runtime=15396
test
2:runtime=22860
test
3:runtime=11197
test
4:runtime=11197
test
5:runtime=12129
test
6:runtime=11663
test
7:runtime=11664
test
8:runtime=53185
test
9:runtime=12130
Run Code Online (Sandbox Code Playgroud)
第一个和第二个运行时区别的原因是什么?提前感谢=)
我尝试使用shutil删除目录及其所有包含的文件,如下所示:
import shutil
from os.path import exists
if exists(path_dir):
shutil.rmtree(path_dir)
Run Code Online (Sandbox Code Playgroud)
不幸的是,我的解决方案不起作用,引发以下错误:
FileNotFoundError: [Errno 2] No such file or directory: '._image1.jpg'
Run Code Online (Sandbox Code Playgroud)
快速搜索表明我并不是唯一一个遇到这个问题的人。在我的理解中,该rmtree功能相当于rm -Rf $DIRshell 命令 - 但事实似乎并非如此。
ps用于重建目的。请创建一个符号链接,例如使用ln -s /path/to/original /path/to/link
我正在使用LIBSVM.在下载包中是一个svm_toy.java文件.我无法弄清楚它是如何工作的.这是源代码:
import libsvm.*;
import java.applet.*;
import java.awt.*;
import java.util.*;
import java.awt.event.*;
import java.io.*;
/**
* SVM package
* @author unknown
*
*/
public class svm_toy extends Applet {
static final String DEFAULT_PARAM="-t 2 -c 100";
int XLEN;
int YLEN;
// off-screen buffer
Image buffer;
Graphics buffer_gc;
// pre-allocated colors
final static Color colors[] =
{
new Color(0,0,0),
new Color(0,120,120),
new Color(120,120,0),
new Color(120,0,120),
new Color(0,200,200),
new Color(200,200,0),
new Color(200,0,200)
};
class point {
point(double x, double y, byte …Run Code Online (Sandbox Code Playgroud) 我是SQLite的新手.我正在Eclipse(Java)中使用它,以防这是相关的.
现在我的问题是我有一个*.db文件,对其内容一无所知.我想知道哪种方式可以获得有关内部表格的一些信息.否则,通过SELECTQuery 正确读取数据库似乎是不可能的.所以基本上我的问题只是这一部分
stmt = c.createStatement();
ResultSet rs = stmt.executeQuery( "SELECT * FROM ???????;" );
while ( rs.next() ) {
int id = rs.getInt("id");
..
Run Code Online (Sandbox Code Playgroud) 我有以下内容 HashMap<String, Double> map = new HashMap<String, Double>();
我怎样才能获得第一个密钥,而不是像这样迭代它:
Iterator it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
System.out.println(pair.getKey() + " = " + pair.getValue());
it.remove();
}
Run Code Online (Sandbox Code Playgroud)
谢谢
Sklearn 清楚地定义了如何使用自己的分类模型1绘制混淆矩阵。但是如何将它与使用数据生成器的 Keras 模型一起使用呢?让我们看一个示例代码:首先我们需要训练模型。
import numpy as np
from keras import backend as K
from keras.models import Sequential
from keras.layers.core import Dense, Dropout, Activation, Flatten
from keras.layers.convolutional import Convolution2D, MaxPooling2D
from keras.preprocessing.image import ImageDataGenerator
from sklearn.metrics import classification_report, confusion_matrix
#Start
train_data_path = 'F://data//Train'
test_data_path = 'F://data//Validation'
img_rows = 150
img_cols = 150
epochs = 30
batch_size = 32
num_of_train_samples = 3000
num_of_test_samples = 600
#Image Generator
train_datagen = ImageDataGenerator(rescale=1. / 255,
rotation_range=40,
width_shift_range=0.2,
height_shift_range=0.2,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
fill_mode='nearest') …Run Code Online (Sandbox Code Playgroud) 在这里,我们可以了解一下OpenCV的基本结构.我的问题是数据类型"标量"到底是什么以及何时使用它.
在这里你可以看到它的定义:
template<typename _Tp> class CV_EXPORTS Scalar_ : public Vec<_Tp, 4>
{
public:
//! various constructors
Scalar_();
Scalar_(_Tp v0, _Tp v1, _Tp v2=0, _Tp v3=0);
Scalar_(const CvScalar& s);
Scalar_(_Tp v0);
//! returns a scalar with all elements set to v0
static Scalar_<_Tp> all(_Tp v0);
//! conversion to the old-style CvScalar
operator CvScalar() const;
//! conversion to another data type
template<typename T2> operator Scalar_<T2>() const;
//! per-element product
Scalar_<_Tp> mul(const Scalar_<_Tp>& t, double scale=1 ) const;
// returns (v0, -v1, …Run Code Online (Sandbox Code Playgroud) 我有麻烦让JSON工作.ObjectMapper无法解决.库已正确导入.
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.json.JSONException;
import net.sf.json.util.*;
import com.fasterxml.jackson.*;
public class Json {
private static final String jsonFilePath = "C:\\Users\\Juergen\\Desktop\\filesForExamples\\mapExample.json";
public static void objectToJSON(HashMap<String, Mat> map) {
//Map<String, Object> mapObject = new HashMap<String, Object>();
ObjectMapper mapper = new ObjectMapper();
try {
objectMapper.writeValue(new File(jsonFilePath), map);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud) 我有以下文字:
I don't like to eat Cici's food (it is true)
我需要将它标记为
['i', 'don't', 'like', 'to', 'eat', 'Cici's', 'food', '(', 'it', 'is', 'true', ')']
我发现以下正则表达式(['()\w]+|\.)拆分如下:
['i', 'don't', 'like', 'to', 'eat', 'Cici's', 'food', '(it', 'is', 'true)']
如何从令牌中取出括号并使其成为自己的令牌?
谢谢你的想法。
java ×6
python ×2
applet ×1
c++ ×1
colors ×1
delete-file ×1
directory ×1
hashmap ×1
json ×1
keras ×1
libsvm ×1
nanotime ×1
objectmapper ×1
opencv ×1
pixel ×1
range ×1
recursion ×1
regex ×1
rgb ×1
scalar ×1
scikit-learn ×1
split ×1
sqlite ×1
string ×1
svm ×1
symlink ×1
system ×1
tokenize ×1
types ×1