我正在尝试运行基本的 MVC 测试
@Test
public void shouldReturnDefaultMessage() throws Exception {
this.mockMvc.perform(get("/")).andDo(print()).andExpect(status().isOk())
.andExpect(content().string(containsString("Hello World")));
}
Run Code Online (Sandbox Code Playgroud)
但是,这将始终导致java.lang.IllegalArgumentException: Header value must not be null
我发现如果我停用 CORS 过滤器,测试将正常运行而不会出错。
我的 SimpleCORSFilter
@Component
public class SimpleCORSFilter implements Filter {
private final Logger log = LoggerFactory.getLogger(SimpleCORSFilter.class);
public SimpleCORSFilter() {
log.info("SimpleCORSFilter init");
}
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin"));
response.setHeader("Access-Control-Allow-Credentials", "true");
//...
chain.doFilter(req, res);
}
} …Run Code Online (Sandbox Code Playgroud) 我正在使用OpenCV来编写视频文件.为了cv::VideoWriter正常工作,对write()函数的调用必须每秒发生30次(对于30fps视频).我发现这个代码使用boost库来实现这一点.我想要同样但std::chrono在我的程序中使用.这是我的实施:
std::chrono::high_resolution_clock::time_point prev = std::chrono::high_resolution_clock::now();
std::chrono::high_resolution_clock::time_point current = prev;
long long difference = std::chrono::duration_cast<std::chrono::microseconds>(current-prev).count();
while(recording){
while (difference < 1000000/30){
current = std::chrono::high_resolution_clock::now();
difference = std::chrono::duration_cast<std::chrono::microseconds>(current-prev).count();
}
theVideoWriter.write(frameToRecord);
prev = prev + std::chrono::high_resolution_clock::duration(1000000000/30);
difference = std::chrono::duration_cast<std::chrono::microseconds>(current-prev).count();
}
theVideoWriter.release();
Run Code Online (Sandbox Code Playgroud)
我不确定这是否是正确的方法,或者是否有更有效的方法.还有什么比投射持续时间更好的long long difference?
这种select单向绑定有效
<select [(ngModel)]="selectedLocation">
<option *ngFor="let location of allLocationNames" [ngValue]="location">{{location.name}}</option>
</select>
Run Code Online (Sandbox Code Playgroud)
selectedLocation将始终包含选定的位置对象。
这种datalist单向绑定似乎不起作用
<h4>Guest: <input type="text" name="guest" [(ngModel)]="selectedGuest" list="options">
<datalist id=options *ngIf="allGuests">
<option *ngFor="let guest of allGuests" [ngValue]="guest">{{guest.companyName}}</option>
</datalist>
</h4>
Run Code Online (Sandbox Code Playgroud)
selectedGuest 将不包含对象,而是包含所选元素的字符串值 (guest.companyName)。
如何在 datalist 示例中获取所选对象?
我有一个函数,用于cv::findContours围绕一个或多个检测到的对象创建矩形,然后我想用它来存储每个对象的裁剪图像.我的问题是cv::findContours在对象周围绘制矩形,但由于我还需要围绕对象的部分背景,我想增加每个矩形的大小.
这可以通过类似的方式轻松完成rectangleVector[i] += cv::Size(10, 10).但问题是,如果检测到的对象正好位于图像的一角,并且我增加了矩形的大小,然后使用矩形来裁剪刚检测到的对象的图像,程序将崩溃,因为矩形不在图像区域了.
我需要以某种方式检查矩形的位置,然后只有增加它的大小,如果生成的矩形不会超出范围.
请在下面找到我的功能.
void ActualRec::objectDetection(){
Mat temp;
thresholdedImage.copyTo(temp);
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
findContours( temp, contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE );
if (contours.size()<5){
vector<vector<Point>> contours_poly( contours.size() );
vector<Rect> boundRect( contours.size() );
for( int i = 0; i < contours.size(); i++ ){
approxPolyDP( Mat(contours[i]), contours_poly[i], 3, true );
boundRect[i] = boundingRect( Mat(contours_poly[i]) );
}
for( int i = 0; i< contours.size(); i++ ){
//won't do the job..
Point BRx = boundRect[i].br();
Point …Run Code Online (Sandbox Code Playgroud) 我有一个Answer类和一个User类.
答案有一个getUser()和用户有一个getPoints()
从答案列表中我想得到一个按点排序的用户哈希集.我试过以下:
Set<User> collectSet = list.stream().map(Answer::getUser)
.sorted(Comparator.comparing(User::getPoints))
.collect(Collectors.toCollection(HashSet::new));
collectSet.forEach(a -> System.out.println(a.toString()));
Run Code Online (Sandbox Code Playgroud)
不幸的是,这似乎没有保留顺序.输出总是不同的.
有趣的是,列表的相同示例可以正常工作
List<User> collectList = list.stream().map(Answer::getUser)
.sorted(Comparator.comparing(User::getPoints))
.collect(Collectors.toList());
collectList.forEach(a -> System.out.println(a.toString()));
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
c++ ×2
angular ×1
c++-chrono ×1
c++11 ×1
java ×1
java-stream ×1
opencv ×1
spring ×1
spring-test ×1