翻转图像以获得镜像效果

时间:2013-02-17 10:44:38

标签: c++ opencv image-processing

我正在制作一个需要翻转画面的视频处理项目。我尝试使用cvFlip,但似乎没有沿y轴翻转(x轴工作......)并导致分段错误。还有其他选择??

cv::Mat dst=src;      //src= source image from cam
cv::flip(dst, dst, 1);     //segmentation fault shown

imshow("flipped",dst);

3 个答案:

答案 0 :(得分:14)

cv::Mat src=imload("bla.png");
cv::Mat dst;               // dst must be a different Mat
cv::flip(src, dst, 1);     // because you can't flip in-place (leads to segfault)

答案 1 :(得分:6)

使用cv::flip并将1作为flipcode传递。

使用示例代码查看您的编辑,您无法翻转到位。您需要一个单独的目标cv::Mat

cv::Mat dst;
cv::flip(src, dst, 1);
imshow("flipped",dst);

答案 2 :(得分:5)

关键是要创建与@AggregateRoot @Entity @Table(name = "news") @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) public class NewsAggregate extends AuditingAggregateRoot implements Serializable { private static final Logger log = LoggerFactory.getLogger(NewsAggregate.class); @Id @Column(name = "news_id") private String newsId; @ManyToOne @JoinColumn(name = "author_id", referencedColumnName = "id") private UserAggregate authorId; @Column(name = "publish_date") private ZonedDateTime publishTime = null; @ManyToMany(cascade = CascadeType.ALL) @JoinTable( name = "tags_news", joinColumns = {@JoinColumn(name = "news_id", referencedColumnName = "news_id")}, inverseJoinColumns = {@JoinColumn(name = "tag", referencedColumnName = "tag")}) @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) private Set<Tags> tags = new HashSet<Tags>(); @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "news_id", referencedColumnName = "news_id") @Fetch(FetchMode.JOIN) private List<NewsTranslation> newsTranslation = new ArrayList<NewsTranslation>(); public NewsAggregate(Set<Tags> tags, UserAggregate authorId) { this.newsId = generateId(authorId.getId()); this.tags = tags; this.authorId = authorId; this.publishTime = ZonedDateTime.now(); } private NewsAggregate(Builder builder) { this.authorId = Preconditions.checkNotNull(builder.authorId); this.publishTime = builder.publishTime; this.tags = Preconditions.checkNotNull(builder.tags); this.newsTranslation = Preconditions.checkNotNull(builder.newsTranslation); } private String generateId(long userId) { return ZonedDateTime.now().toInstant().toEpochMilli() + "_" + userId; } public static NewsAggregate createNews(Set<Tags> tags, UserAggregate authorId, CreateNewsDto createNewsDto) { NewsAggregate news = new NewsAggregate(tags, authorId); log.info(">>>>>>>>>>>>>>>>>> news_id = "+news.getNewsId()); NewsLangId newsLangId = new NewsLangId(news.getNewsId(), "en"); NewsTranslation newsTranslation = new NewsTranslation(newsLangId, createNewsDto.getTitle(), createNewsDto.getShortDescription(), createNewsDto.getLongDescription()); List<NewsTranslation> newsTranslations = new ArrayList<>(); newsTranslations.add(newsTranslation); news.addTranslation(newsTranslations); return news; } private void addTranslation(List<NewsTranslation> newsTranslations) { this.newsTranslation = newsTranslations; } 完全相同的dst

src